DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
By default, it uses the MobX state management library, but this is optional and can be used as a pure JS library.
Basic usage
import { Collection, Model, Attribute } from'@datx/core';
import { computed } from'mobx';
classPersonextendsModel {
publicstatictype = 'person'; // Unique name of the model class@Attribute()
public name!: string; // A normal property without a default value@Attribute()
public surname!: string;
@Attribute({ toOne: Person })
public spouse?: Person; // A reference to a Person model@computedpublicgetfullName() {
// Standard MobX computed propsreturn`${this.name}${this.surname}`;
}
}
classAppDataextendsCollection {
publicstatic types = [Person]; // A list of models available in the collection
}
const store = newAppData();
const john = store.add(newPerson({ name: 'John', surname: 'Smith' })); // Add a model instance to the storeconst jane = store.add({ name: 'Jane', surname: 'Smith', spouse: john }, Person); // Add a model to the store
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.
The npm package @datx/core receives a total of 234 weekly downloads. As such, @datx/core popularity was classified as not popular.
We found that @datx/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 7 open source maintainers collaborating on the project.
Last updated on 05 Sep 2023
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.
ua-parser-js is set to drop the MIT license and adopt a controversial dual AGPLv3 + PRO licensing model in its upcoming v2.0 release, raising significant concerns among developers and enterprise users.