Last active
May 16, 2017 12:26
-
-
Save aGuyNamedJonas/bdd48c26fb2c49246b886271aafef0b0 to your computer and use it in GitHub Desktop.
Change Trigger Example slim-redux v0.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// changes/todo.js | |
import { changeTrigger } from 'slim-redux'; | |
export const addTodo = changeTrigger('ADD_TODO', (label, state) => { | |
const newId = state.todos.map((max, todo) => Math.max(max, todo,id), 0) + 1; | |
return { | |
...state, | |
todos: [ | |
...state.todos, | |
{id: newId, label: label, checked: false}, | |
] | |
}; | |
}); | |
// main.js | |
import { createSlimReduxStore } from 'slim-redux' | |
import { addTodo } from './changes/todo'; | |
// Per default, createSlimReduxStore makes the store instance available in the global scope. | |
// You can deactivate this behavior, and manually pass in the appropriate store instance when | |
// invoking change trigger functions | |
const store = createSlimReduxStore({todos:[]}); | |
// Notice how we don't need to initialize anything anymore, | |
// we just call the change trigger to use it. The store is | |
// automatically placed in the global scope | |
addTodo('Get Milk'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment