Skip to content

Instantly share code, notes, and snippets.

@strzibny strzibny/redux_store.rb
Last active Jan 27, 2018

Embed
What would you like to do?
Basic ReduxStore implemented in Ruby
class ReduxStore
attr_reader :current_state
def initialize(reducer)
@reducer = reducer
@listeners = []
@current_state = nil
dispatch({})
end
def dispatch(action)
@current_state = @reducer.call(@current_state, action)
@listeners.each { |l| l.call }
end
def subscribe(listener)
@listeners.push(listener)
->{ @listeners.delete(listener) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.