Created
May 31, 2017 17:23
-
-
Save rblalock/4e0cc42bbd13953bace1ac1c8299909f to your computer and use it in GitHub Desktop.
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
// 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