Module: BubbleWrap::KVO

Defined in:
motion/core/kvo.rb

Constant Summary collapse

COLLECTION_OPERATIONS =
[ NSKeyValueChangeInsertion, NSKeyValueChangeRemoval, NSKeyValueChangeReplacement ]
DEFAULT_OPTIONS =
NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld

Instance Method Summary collapse

Instance Method Details

#observe(target, key_path, &block) ⇒ Object



24
25
26
27
# File 'motion/core/kvo.rb', line 24

def observe(target, key_path, &block)
  target.addObserver(self, forKeyPath:key_path, options:DEFAULT_OPTIONS, context:nil) unless registered?(target, key_path)
  add_observer_block(target, key_path, &block)
end

#unobserve(target, key_path) ⇒ Object



29
30
31
32
33
34
# File 'motion/core/kvo.rb', line 29

def unobserve(target, key_path)
  return unless registered?(target, key_path)

  target.removeObserver(self, forKeyPath:key_path)
  remove_observer_block(target, key_path)
end

#unobserve_allObject



36
37
38
39
40
41
42
43
44
45
# File 'motion/core/kvo.rb', line 36

def unobserve_all
  return if @targets.nil?

  @targets.each do |target, key_paths|
    key_paths.each_key do |key_path|
      target.removeObserver(self, forKeyPath:key_path)
    end  
  end
  remove_all_observer_blocks
end