lib/glimmer/data_binding/observable_array.rb in glimmer-2.2.1 vs lib/glimmer/data_binding/observable_array.rb in glimmer-2.2.2
- old
+ new
@@ -235,10 +235,25 @@
else
super
end
end
+ def filter!(&block)
+ if block_given?
+ old_array = Array.new(self)
+ super(&block).tap do
+ (old_array - self).each do |old_value|
+ unregister_dependent_observers(old_value)
+ remove_element_observers(old_value)
+ end
+ notify_observers
+ end
+ else
+ super
+ end
+ end
+
def shuffle!(hash = nil)
(hash.nil? ? super() : super(random: hash[:random])).tap { notify_observers }
end
def slice!(arg1, arg2=nil)
@@ -289,9 +304,20 @@
unregister_dependent_observers(old_value)
remove_element_observers(old_value)
end
notify_observers
end
+ end
+ end
+
+ def replace(other_array)
+ old_array = Array.new(self)
+ super(other_array).tap do
+ (old_array - self).each do |old_value|
+ unregister_dependent_observers(old_value)
+ remove_element_observers(old_value)
+ end
+ notify_observers
end
end
def unregister_dependent_observers(old_value)
return unless old_value.is_a?(ObservableModel) || old_value.is_a?(ObservableArray)