The tinyRedux library is an simplified version of Redux which provides the same capabilities.
CDN: https://cdn.rawgit.com/frentsel/tinyRedux/master/tinyRedux.js
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'});