Class: React::StateWrapper
- Inherits:
- BasicObject
- Defined in:
- lib/react/state.rb
Instance Method Summary collapse
- #[](state) ⇒ Object
- #[]=(state, new_value) ⇒ Object
-
#initialize(native, from) ⇒ StateWrapper
constructor
A new instance of StateWrapper.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(native, from) ⇒ StateWrapper
Returns a new instance of StateWrapper.
3 4 5 6 |
# File 'lib/react/state.rb', line 3 def initialize(native, from) @state_hash = Hash.new(`#{native}.state`) @from = from end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/react/state.rb', line 16 def method_missing(method, *args) if match = method.match(/^(.+)\!$/) if args.count > 0 current_value = State.get_state(@from, match[1]) State.set_state(@from, $1, args[0]) current_value else current_state = State.get_state(@from, match[1]) State.set_state(@from, $1, current_state) Observable.new(current_state) do |update| State.set_state(@from, $1, update) end end else State.get_state(@from, method) end end |