Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
datx-network
Advanced tools
Readme
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/network
is a datx mixin that adds a networking layer support. It can be used with any REST-like API and probably also other types of an API.
import { Collection, Model, Attribute } from '@datx/core';
import { BaseRequest, collection, setUrl } from '@datx/network';
class Person extends Model {
public static type = 'person'; // Unique name of the model class
@Attribute()
public name: string; // A normal observable property without a default value
@Attribute()
public surname: string;
@Attribute({ toOne: Person })
public spouse?: Person; // A reference to a Person model
@computed
public get fullName() {
// Standard MobX computed props
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();
// Create a base request with a basic configuration (baseUrl and linked collection)
const baseRequest = new BaseRequest('https://example.com').pipe(collection(store));
// Create separate request points
const getPerson = baseRequest.pipe<Person>(setUrl('/people/{id}', Person));
const getPeople = baseRequest.pipe<Array<Person>>(setUrl('/people', Person));
// Pure JS loading
const peopleResponse = await getPeople.fetch();
// Loading in a React component
const PersonInfo = ({ userId }) => {
const [response, loading, error] = getPerson.useHook({ id: userId });
if (loading || error) {
return null;
}
const user = response.data;
return <div>{user.fullName}</div>;
};
Note: @datx/network
has a peer dependency to mobx@^4.2.0
or mobx@^5.5.0
, so don't forget to install the latest MobX version:
npm install --save @datx/network mobx
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. 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.
Having issues with the library? Check out the troubleshooting page or open an issue.
The MIT License
@datx/network is maintained and sponsored by Infinum.
FAQs
DatX network layer
We found that datx-network demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
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.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).