Created
June 22, 2012 11:08
-
-
Save melvynhills/2972123 to your computer and use it in GitHub Desktop.
Spine plugin for dirty model attributes
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
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 | |
### | |
Usage example: | |
class Model extends Spine.Model | |
@configure "Model", "firstname", "lastname" | |
@extend Spine.Model.Dirty | |
class Controller extends Spine.Controller | |
constructor: -> | |
Model.bind "change:lastname", (model, lastname) => | |
@log model, lastname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment