An Interest In:
Web News this Week
- March 26, 2024
- March 25, 2024
- March 24, 2024
- March 23, 2024
- March 22, 2024
- March 21, 2024
- March 20, 2024
August 16, 2022 05:15 pm GMT
Original Link: https://dev.to/vyquocvu/i-wrote-a-state-management-npm-any-state-291n
I wrote a state management npm - Any State
Features:
Lightweight object state management
Open Source Project
Small App Size (~2Kb)
Easy to use with nay framework, just a callback on change
About:
AnyState is an open source programs built using Typescript (for a more secure environment).
Usage
Initialize anyState object with createStore()
const anyState = createStore({ name: 'John', age: 30, children: [{ name: 'Bob', age: 5, }] });
Set state
anyState.setState({ name: 'John', age: 30, children: [{ name: 'Bob', age: 5, }] });
Get state
const state = anyState.getState();
Set item
// const path = 'name'; const path = 'children[0].name'; // the path to the item anyState.setItem(path, 'Jane');
Get item
const path = 'children[0]'; const child = anyState.getItem(path);
Watch onChange
const path = 'name'; // path to item anyState.watch(path, (nextState, prevState) => { // do anything });
Examples
Links:
GitHub: https://github.com/vyquocvu/anystate
Npm: https://www.npmjs.com/package/anystate
MySite: https://vyquocvu.co/
Happy coding!
Accepted any advices.
Original Link: https://dev.to/vyquocvu/i-wrote-a-state-management-npm-any-state-291n
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To