lib/motion_bindable/strategy.rb in motion_bindable-0.2.4 vs lib/motion_bindable/strategy.rb in motion_bindable-0.2.5

- old
+ new

@@ -39,11 +39,11 @@ start_listen self end def unbind - @watching = nil + @watching = false end private # Methods to leave alone def attribute @@ -76,19 +76,22 @@ if respond_to?(:start_observing_object) then start_observing_object elsif respond_to?(:refresh_object) && respond_to?(:on_object_change) sides << :object end + @watching = true watch(sides) end def watch(sides) - @watching = dispatcher.async do - bound_result = refresh_bound if sides.include?(:bound) - object_result = refresh_object if sides.include?(:object) - on_bound_change(bound_result) if bound_result - on_object_change(object_result) if object_result - dispatcher.after(WATCH_TICK) { watch(sides) } unless @watching + dispatcher.async do + if @watching + bound_result = refresh_bound if sides.include?(:bound) + object_result = refresh_object if sides.include?(:object) + on_bound_change(bound_result) if bound_result + on_object_change(object_result) if object_result + dispatcher.after(WATCH_TICK) { watch(sides) } + end end end def dispatcher @dispatcher ||= begin