Skip to content

Instantly share code, notes, and snippets.

@Kelin2025
Created June 16, 2019 19:35
Show Gist options
  • Save Kelin2025/49b2f67a07fa82914ae9bef390a6c250 to your computer and use it in GitHub Desktop.
Save Kelin2025/49b2f67a07fa82914ae9bef390a6c250 to your computer and use it in GitHub Desktop.
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