0.18.0 • Published 12 days ago
@tinijs/store v0.18.0
TiniJS Store
The state management module for the TiniJS framework.
It is very small, under ~1KB at around 50 lines of code.
Install
To manually install the module: npm i @tinijs/store
It is recommended to download the Skeleton for a ready-to-use structured project.
For more, please visit: https://tinijs.dev (TODO)
Usage
- Create a store
stores/main.ts
import {createStore} from '@tinijs/store';
export const mainStore = createStore({
foo: 'bar'
});
- Access a state
import {mainStore} from './stores/main';
const foo = mainStore.foo;
- Subscribe to a state
import {TiniComponent, Component, Reactive} from '@tinijs/core';
import {Subscribe} from '@tinijs/store';
import {mainStore} from './stores/main';
@Component()
export class MyComponent extends TiniComponent {
// 'this.foo' will be updated when 'mainStore.foo' changes
// it is reactive by default
@Subscribe(mainStore) foo = mainStore.foo;
// use a different variable name
@Subscribe(mainStore, 'foo') xyz = mainStore.foo;
// to turn of reactive
// set the third argument to false
@Subscribe(mainStore, null, false) foo = mainStore.foo;
// or subscribe manually
// NOTE: remember to unsubscribe when the component is destroyed
onInit() {
this.fooSubscription = mainStore.subscribe('foo', value => {
// do something
});
}
onDestroy() {
this.fooSubscription();
}
}
- Mutate a state
import {mainStore} from './stores/main';
// assign a new value
mainStore.foo = 'bar2';
// or, using the 'commit' method
mainStore.commit('foo', 'bar3');
API
// TODO
Developement
- Create a home for TiniJS:
mkdir TiniJS && cd TiniJS
- Fork the repo
- Install dependencies:
cd store && npm i
- Make changes & preview locally:
npm run build && npm pack
- Push changes & create a PR 👌
License
@tinijs/store is released under the MIT license.
0.18.0
12 days ago
0.17.0-alpha.0
1 month ago
0.17.0-alpha.1
1 month ago
0.17.0
1 month ago
0.16.0
4 months ago
0.15.1
4 months ago
0.15.0
4 months ago
0.14.1
4 months ago
0.14.0
4 months ago
0.13.0
5 months ago
0.10.0
8 months ago
0.1.0
9 months ago
0.3.0
9 months ago
0.2.0
9 months ago
0.1.1
9 months ago
0.11.0
6 months ago
0.9.0
8 months ago
0.12.0
6 months ago
0.8.0
9 months ago
0.5.0
9 months ago
0.4.0
9 months ago
0.6.0
9 months ago
0.0.2
1 year ago
0.0.1
1 year ago