Skip to content

frentsel/tinyRedux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinyRedux

preview

The tinyRedux library is an simplified version of Redux which provides the same capabilities.

Download

CDN: https://cdn.rawgit.com/frentsel/tinyRedux/master/tinyRedux.js

Basic Usage

Create some data store for application

var data = [
  'Apple',
  'Banana',
  'Orange'
];

Pass created data and object of handlers into Store constructor fro create instance of store.

var store = new Store(data, {
  GET_ALL: function (state) {
    return state;
  },
  ADD: function (state, item) {
    state.push(item);
    return state;
  },
  DELETE: function (state, item) {
    var index = state.indexOf(item);
    state.splice(index, 1);
    return state;
  },
  UPDATE: function (state, obj) {
    var index = state.indexOf(obj.from);
    state[index] = obj.to;
    return state;
  }
});

Subscribe on all changes of state.

store.subscribe(console.log);

And let's change a storage.

store.dispatch('GET_ALL');
store.dispatch('ADD', 'Melon');
store.dispatch('DELETE', 'Orange');
store.dispatch('UPDATE', {from: 'Orange', to: 'Peach'});

About

Simplified implementation of Redux.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors