simple-state-management
v1.0.6
Published
Simple state management library
Downloads
22
Maintainers
Readme
Simple State Management
simple state management library for frontend
Installation
$ npm install --save simple-state-management
Demo
https://simple-state-management.netlify.app/
$ cd demo
$ npm install .
$ npm run start
-> localhost:8080
Real Application Demo
https://hostile-architecture.org/
Usage
Initialize library
stores.js
import SimpleStateManagement from 'simple-state-management';
import actions from './actions';
import getters from './getters';
import mutations from './mutations';
import states from './states';
export default new SimpleStateManagement({
actions,
mutations,
getters,
states
});
Subscribe in your components
app.js
import store from './stores';
...
// Fire dispatch event for api fetching or something
store.dispatch('todos.fetchList');
...
// Subcribe event
this.unsbscribe = store.subscribe('todos', () => {
this.list = store.getters('todos.list');
this.render();
});
...
// Render view
render() {
console.log('render => ', this.list);
}
...
unmount() {
this.unsbscribe();
}