Created
October 1, 2014 21:06
-
-
Save sxross/7cfa64b330beacad1409 to your computer and use it in GitHub Desktop.
MotionModel Watchable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MotionModel | |
module Watchable | |
def self.included(base) | |
# uncomment if private class methods | |
# base.extend(PrivateClassMethods) | |
base.extend(PublicClassMethods) | |
# base.instance_eval do | |
# Any instance specific code | |
# end | |
end | |
module PublicClassMethods | |
def watch(&block) | |
observer = BW::App.notification_center.observe 'MotionModelDataDidChangeNotification' do |notification| | |
if notification.object.is_a?(self.ancestors[0]) | |
block.call notification | |
end | |
end | |
observer | |
end | |
def stop_watching(observer) | |
App.notification_center.unobserve observer | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment