Skip to content

Instantly share code, notes, and snippets.

@aeischeid
Forked from Thibaut/dirty.js.coffee
Created July 18, 2013 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeischeid/6026615 to your computer and use it in GitHub Desktop.
Save aeischeid/6026615 to your computer and use it in GitHub Desktop.
Include =
savePrevious: ->
@constructor.records[@id].previousAttributes = @attributes()
revertChanges: ->
if @previousAttributes
attrs = {}
attrs[key] = @previousAttributes[key] ? null for key in @constructor.attributes
@load attrs
@savePrevious()
previous: (attr) ->
@previousAttributes?[attr]
hasChanged: (attr) ->
@previous(attr) isnt @[attr]
Spine.Model.Dirty =
extended: ->
@bind 'refresh', (records) ->
record.savePrevious() for record in records
@bind 'save', (record) ->
record.savePrevious()
@include Include
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment