Skip to content
/ store Public

Basic Store. You can read values. Changing values requires an action that triggers reducers.

License

Notifications You must be signed in to change notification settings

ripter/store

Repository files navigation

Store

The idea of the store, is that the data/state is only changed in predictable and testable ways. [reducers, action] This way the logic can be tested and updated as the application grows. New features can be tested by adding or removing reducers or adding new actions. You can be notified when an action happens by setting an onChange function.

// create the store
// Set the initial state, a Javascript Object
// Then the reducers that make up the logic of how the state changes.
// Finally a function to be called whenever the state changes.
const store = new Store({foo: 'bar'}, [
  reduceFunctions,
], onChange);

// trigger a change
store.action({
  type: 'select',
  id: 'one',
});

// get the state
// supports keypaths, like 'foo.bar[0]'
const init = store.get('foo');

// Write reducers
function reducer(state, action, pushNextAction) {
  if (action.type !== 'select') { return state; }

  if (afterCurrentAction) {
    pushNextAction({type: 'nextAction'});
  }
  return state;  
}

Install via CDN

  <script src="https://unpkg.com/@ripter/store@latest/dist/store-iife.js"></script>

Install via NPM

npm install --save @ripter/store

About

Basic Store. You can read values. Changing values requires an action that triggers reducers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published