GithubHelp home page GithubHelp logo

infinum / datx Goto Github PK

View Code? Open in Web Editor NEW
137.0 7.0 6.0 31 MB

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.

Home Page: https://datx.dev

License: MIT License

TypeScript 95.49% JavaScript 4.01% CSS 0.48% Shell 0.01%
mobx data state-management data-store model collection prop hacktoberfest open-source javascript

datx's Introduction

DatX

Unit tests

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.


Basic usage

import { Collection, Model, Field } from '@datx/core';

class Person extends Model {
  public static type = 'person'; // Unique name of the model class

  @Field()
  public name!: string; // A normal property without a default value

  @Field()
  public surname!: string;

  @Field({ toOne: Person })
  public spouse?: Person; // A reference to a Person model

  public get fullName() {
    // Standard JS getter
    return `${this.name} ${this.surname}`;
  }
}

class AppData extends Collection {
  public static types = [Person]; // A list of models available in the collection
}

const store = new AppData();
const john = store.add(new Person({ name: 'John', surname: 'Smith' })); // Add a model instance to the store
const jane = store.add({ name: 'Jane', surname: 'Smith', spouse: john }, Person); // Add a model to the store

Getting started

npm install --save @datx/core

Polyfilling

The lib makes use of the following features that are not yet available everywhere. Based on your browser support, you might want to polyfill them:

How to add the polyfills.

Concepts

The library contains two main classes - Model and Collection.

A collection contains models of any kind (they should however be listed in the types property), while a model can be in a single collection (but doesn't need to be in any).

Models also include some useful methods and properties, but if they're in collision with your data/logic, you can use a PureModel class.

Mixins

Mixins are additional plugins that can enhance the regular models and collections. Available mixins:

  • withActions (model) - Adds some helper methods to the model - already included in the Model class, but not in the PureModel class
  • withMeta (model) - Adds some helpful meta data to the model - already included in the Model class, but not in the PureModel class
  • withPatches (model, collection) - Adds patch support to models and collections
  • datx-jsonapi (model, collection and view) - Adds the JSON API features to the model, collection and view

To check out what are the planed future mixins, check out the issues.

Want to make your own mixin? Check out the guide.

API reference

Troubleshooting

Having issues with the library? Check out the troubleshooting page or open an issue.


Build Status

License

The MIT License

Credits

datx is maintained and sponsored by Infinum.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.