@treblegsm/core v1.0.0-alpha.59
Treble Global State Manager
TrebleGSM is a framework agnostic global state manager that makes working with global state in js apps fun. This is going to replace package 'treble-gsm' (which is React only) in the near future.
This is the core package. Even though this can be used as a stand alone package, it was meant to provide a foundation for Framework specific packages.
- Create a new
Store
import TrebleGSM from '@treblegsm/core';
export const Store = TrebleGSM.Store();
- Add initial state to
Store
Store.addItem({
key: 'name',
state: 'Ash Ketchum'
});
Store.addItem({
key: 'age',
state: 10
});
- Update state
Store.setState('name', 'Gary Oak') //key, new state
- Get state
Store.getState('name') //key
- Listen for state changes
Store.onDispatch((dispatchItem) => {
if (dispatchItem.key === 'name') {
console.log(dispatchItem.state)
}
});
//initial console.log output
//name: Ash Ketchum
//new console.log output
//name: Gary Oak
9 months ago
9 months ago
9 months ago
9 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago