simple-state-management

Simple state management library

Usage no npm install needed!

<script type="module">
  import simpleStateManagement from 'https://cdn.skypack.dev/simple-state-management';
</script>

README

Simple State Management

License: MIT npm version

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();
}