lib/command_handlers/models/observable_model.rb in glimmer-0.3.1 vs lib/command_handlers/models/observable_model.rb in glimmer-0.3.2
- old
+ new
@@ -52,10 +52,11 @@
end
#TODO upon updating values, make sure dependent observers are cleared (not added as dependents here)
def add_property_writer_observers(property_name)
property_writer_name = "#{property_name}="
+ method(property_writer_name)
ensure_array_object_observer(property_name, send(property_name))
begin
method("__original_#{property_writer_name}")
rescue
instance_eval "alias __original_#{property_writer_name} #{property_writer_name}"
@@ -67,10 +68,13 @@
notify_observers('#{property_name}')
ensure_array_object_observer('#{property_name}', value, old_value)
end
end_eval
end
+ rescue => e
+ # ignore writing if no property writer exists
+ Glimmer.logger.debug "No need to observe property writer: #{property_writer_name}\n#{e.message}\n#{e.backtrace.join("\n")}"
end
def unregister_dependent_observers(property_name, old_value)
# TODO look into optimizing this
return unless old_value.is_a?(ObservableModel) || old_value.is_a?(ObservableArray)
@@ -79,10 +83,9 @@
end
end
def ensure_array_object_observer(property_name, object, old_object = nil)
return unless object.is_a?(Array)
- object.extend(ObservableArray) unless object.is_a?(ObservableArray)
array_object_observer = array_object_observer_for(property_name)
array_object_observer.observe(object)
property_observer_list(property_name).each do |observer|
observer.add_dependent([self, property_name] => [array_object_observer, object, nil])
end