Skip to content

Instantly share code, notes, and snippets.

@rblalock
Created May 31, 2017 17:23
Show Gist options
  • Save rblalock/4e0cc42bbd13953bace1ac1c8299909f to your computer and use it in GitHub Desktop.
Save rblalock/4e0cc42bbd13953bace1ac1c8299909f to your computer and use it in GitHub Desktop.
// Modx
class Todo {
id = Math.random();
@observable text;
@observable completed = false;
constructor(text) {
this.text = text;
}
}
class Todos {
@observable todos = [];
add (todo) {
this.todos.push(todo);
}
}
// REDUX
const todo = (state = {}, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
}
default:
return state
}
}
const todos = (state = [], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
todo(undefined, action)
]
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment