Created
June 4, 2012 05:44
-
-
Save sishen/2866558 to your computer and use it in GitHub Desktop.
Dirty plugin for SpineJS.
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
Spine ?= require('spine') | |
Include = | |
savePrevious: -> | |
@constructor.records[@id].previousAttributes = @attributes() | |
Spine.Model.Dirty = | |
extended: -> | |
@bind 'refresh', -> | |
@each (record) -> record.savePrevious() | |
@bind 'save', (record) -> | |
if record.previousAttributes? | |
for key in record.constructor.attributes when key of record | |
if record[key] isnt record.previousAttributes[key] | |
record.trigger('change:'+key, record[key]) | |
record.savePrevious() | |
@include Include |
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
So the model object can bind the event "change:#{field} to trigger event when the field value is changed. | |
By default it's off and if need this feature, the model should extend Spine.Model.Dirty. | |
A sample case. | |
class User extends Spine.Model | |
@extend Spine.Model.Dirty | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment