https://github.com/monntecc/store
Simple, light-way state library for JS/TS
https://github.com/monntecc/store
javascript node npm reactive store typescript
Last synced: 3 months ago
JSON representation
Simple, light-way state library for JS/TS
- Host: GitHub
- URL: https://github.com/monntecc/store
- Owner: monntecc
- License: mit
- Created: 2023-09-24T20:34:46.000Z (almost 3 years ago)
- Default Branch: latest
- Last Pushed: 2023-09-27T10:18:05.000Z (almost 3 years ago)
- Last Synced: 2025-01-09T02:52:10.596Z (over 1 year ago)
- Topics: javascript, node, npm, reactive, store, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@nylestroke/store
- Size: 62.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## @nylestroke/store
@nylestroke/store is a simple state container for JavaScript apps.
It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test.
## Installation
```
npm install @nylestroke/store
```
For more details, see [the NPM page](https://npmjs.com/package/@nylestroke/store).
## Basic Example
```js
import { Store } from '@nylestroke/store';
const store = new Store();
const firstCallback = state => {
console.log('first callback ', state); // callback function
};
const firstConfig = state => { // there you can state, as you want
return state;
};
const secondCallback = state => {
console.log('second callback ', state);
};
const secondConfig = state => {
return [state];
};
store.subscribe(firstCallback, firstConfig); // call subscription with callback and configuration
store.subscribe(secondCallback, secondConfig);
store.setState({ a: 1 }); // add value to state (not set)
store.clearState(); // clear the state
store.setState({ a: 2 });
store.setState({ b: 1 });
store.cutState('b'); // delete key from a state
store.setState({ b: 2 });
```
## License
[MIT](https://github.com/nylestroke/store/blob/master/LICENSE)