Created
March 9, 2013 00:19
-
-
Save jareiko/5121636 to your computer and use it in GitHub Desktop.
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
createAttributeMonitor = -> | |
monitored = Object.create null | |
(parentModel, name) -> | |
bubbleEvent = (event, args...) -> | |
return unless event.startsWith 'change:' | |
parentModel.trigger "change:#{name}.#{event[7..]}", args... | |
value = parentModel.get name | |
oldValue = monitored[name] | |
if oldValue? | |
return if value is oldValue | |
oldValue.off 'all', bubbleEvent | |
if value instanceof Backbone.Model or value instanceof Backbone.Collection | |
monitored[name] = value | |
value.on 'all', bubbleEvent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment