Created
April 13, 2011 12:15
-
-
Save walm/917439 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* class JooseX.Attribute.Dirty | |
* | |
* Add _isDirty_ property if an attribute has been changed with setter method. | |
* | |
**/ | |
Role('JooseX.Attribute.Dirty', { | |
override : { | |
getSetter : function() { | |
var self = this | |
var original = self.SUPER() | |
var init = Joose.O.isFunction(self.init) ? null : self.init | |
if ( !self.writeable ) return original | |
return function () { | |
var oldValue = self.hasValue(this) ? self.getValueFrom(this) : init | |
var res = original.apply(this, arguments) | |
var newValue = self.getValueFrom(res) | |
if ( !this.isDirty ) this.isDirty = ( newValue != oldValue ) | |
return res | |
} | |
} | |
} | |
}) | |
Joose.Managed.Attribute.meta.extend({ | |
does : [ JooseX.Attribute.Dirty ] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment