Created
June 16, 2019 19:35
-
-
Save Kelin2025/49b2f67a07fa82914ae9bef390a6c250 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
const $names = createStore([]) | |
const $completed = createStore([]) | |
const $todos = combine( | |
$names, | |
$completed, | |
(names, completed) => names.map((name, i) => ({ name, completed: completed[i] }) | |
) | |
$names | |
.on(addTodo, (state, { name }) => [...state, name]) | |
$completed | |
.on(addTodo, (state, { completed }) => [...state, completed]) | |
.on(toggleTodo, (state, idx) => state.map((cur, i) => i === idx ? { ...cur, completed: !cur.completed } : cur)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment