Skip to content

Instantly share code, notes, and snippets.

@walm
Created April 13, 2011 12:15
Show Gist options
  • Save walm/917439 to your computer and use it in GitHub Desktop.
Save walm/917439 to your computer and use it in GitHub Desktop.
/**
* 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