Last active
November 4, 2016 02:07
-
-
Save jtompkins/3fc362439cec96bd8b1df6aa334e2b2e to your computer and use it in GitHub Desktop.
A sample of the new Rbdux API.
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
require 'rbdux' | |
Rbdux::configure do | |
store Rbdux::Stores::MemoryStore.with_state do | |
visibility: :hide_completed, | |
todos: [] | |
end | |
actions do | |
define :toggle_visibility | |
define :toggle_todo | |
define :new_todo do |store, payload| | |
puts payload | |
end | |
end | |
middleware Rbdux::Middleware::Thunk.new | |
reduce :new_todo do |state, payload| | |
state.add(payload) | |
end | |
reduce :toggle_visibility do |state, payload| | |
state == :hide_completed ? :show_completed : :hide_completed | |
end | |
reduce :toggle_todo do |state, payload| | |
idx = payload - 1 | |
todo = state[idx] | |
todo.completed = !todo.completed unless todo.nil? | |
state.put(idx, todo) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment