lib/react/state.rb in hyper-react-0.10.0 vs lib/react/state.rb in hyper-react-0.11.0

- old
+ new

@@ -13,19 +13,20 @@ @state_hash[state] = new_value end def method_missing(method, *args) if match = method.match(/^(.+)\!$/) + key_name = $1 if args.count > 0 current_value = State.get_state(@from, match[1]) - State.set_state(@from, $1, args[0]) + State.set_state(@from, key_name, args[0]) current_value else current_state = State.get_state(@from, match[1]) - State.set_state(@from, $1, current_state) + State.set_state(@from, key_name, current_state) Observable.new(current_state) do |update| - State.set_state(@from, $1, update) + State.set_state(@from, key_name, update) end end else State.get_state(@from, method) end @@ -156,11 +157,11 @@ end current_observers.delete(@current_observer) end def set_state_context_to(observer, rendering = nil) # wrap all execution that may set or get states in a block so we know which observer is executing - if `typeof window.reactive_ruby_timing !== 'undefined'` + if `typeof Opal.global.reactive_ruby_timing !== 'undefined'` @nesting_level = (@nesting_level || 0) + 1 start_time = Time.now.to_f observer_name = (observer.class.respond_to?(:name) ? observer.class.name : observer.to_s) rescue "object:#{observer.object_id}" end saved_current_observer = @current_observer @@ -169,10 +170,10 @@ return_value = yield return_value ensure @current_observer = saved_current_observer @rendering_level -= 1 if rendering - @nesting_level = [0, @nesting_level - 1].max if `typeof window.reactive_ruby_timing !== 'undefined'` + @nesting_level = [0, @nesting_level - 1].max if `typeof Opal.global.reactive_ruby_timing !== 'undefined'` return_value end def states @states ||= Hash.new { |h, k| h[k] = {} }