Last active
October 19, 2015 02:42
-
-
Save antonycourtney/320a6036169975c8b08d to your computer and use it in GitHub Desktop.
Responses to user interaction in oneref-todomvc
This file contains 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
/** | |
* todoActions.js -- event handlers for TodoMVC app | |
*/ | |
import TodoItem from './todoItem'; | |
export function create(text,updater) { | |
updater((state) => state.addItem(new TodoItem(text))); | |
} | |
export function toggleComplete(item,updater) { | |
const updatedItem = item.set('complete', !item.complete); | |
updater((state) => state.addItem(updatedItem)); | |
} | |
export function updateText(item,text,updater) { | |
const updatedItem = item.set('text',text); | |
updater((state) => state.addItem(updatedItem)); | |
} | |
export function destroy(id,updater) { | |
updater((state) => state.removeItem(id)); | |
} | |
export function destroyCompleted(updater) { | |
updater((state) => { | |
const completedIds = state.getAll().filter((item) => item.complete).map((item) => item.id); | |
return completedIds.reduce((s,id) => s.removeItem(id),state); | |
}); | |
} | |
export function toggleCompleteAll(updater) { | |
updater((state) => { | |
const targetVal = !(state.areAllComplete()); | |
// We'll set completed state of all items to targetVal: | |
const updItems = state.getAll().map((item) => item.set('complete', targetVal)); | |
const nextState = updItems.reduce((st,item) => st.addItem(item), state); | |
return nextState; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment