DatX is an opinionated data store for use with the MobX state management library. It features support for simple observable property definition, references to other models and first-class TypeScript support.
@datx/jsonapi is a datx mixin that adds JSON API support.
Basic usage
import { Collection, Model, Attribute } from'@datx/core';
import { jsonapiCollection, jsonapiModel } from'@datx/jsonapi';
import { computed } from'mobx';
classPersonextendsjsonapiModel(Model) {
publicstatictype = 'person'; // Unique name of the model class@Attribute()
publicname: string; // A normal observable property without a default value@Attribute()
publicsurname: string;
@Attribute({ toOne: Person })
public spouse?: Person; // A reference to a Person model@computedpublicgetfullName() {
// Standard MobX computed propsreturn`${this.name}${this.surname}`;
}
}
classAppDataextendsjsonapiCollection(Collection) {
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 storeawait john.save(); // POST to the serverconst people = await store.fetchAll(Person); // Get all people from the server
Getting started
Note: @datx/jsonapi has a peer dependency to mobx@^4.2.0 or mobx@^5.5.0, so don't forget to install the latest MobX version:
How to add the polyfills.
Note: Fetch API is not included in the polyfills mentioned in the Troubleshooting page. Instead, you need to add it as a separate library. If you don't have any special requirements (like server-side rendering), you can use the window.fetch polyfill.
The npm package @datx/jsonapi receives a total of 220 weekly downloads. As such, @datx/jsonapi popularity was classified as not popular.
We found that @datx/jsonapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 7 open source maintainers collaborating on the project.
Package last updated on 20 Apr 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.
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.
Microsoft has released an open source toolkit for enforcing runtime security policies on AI agents as adoption accelerates faster than governance controls.