Skip to content

Instantly share code, notes, and snippets.

@sishen sishen/Usage:
Created Jun 4, 2012

What would you like to do?
Dirty plugin for SpineJS.
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])
@include Include
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.