Skip to content

Instantly share code, notes, and snippets.

@Thibaut
Created August 28, 2012 07:11
Show Gist options
  • Select an option

  • Save Thibaut/3495767 to your computer and use it in GitHub Desktop.

Select an option

Save Thibaut/3495767 to your computer and use it in GitHub Desktop.

Revisions

  1. Thibaut created this gist Aug 28, 2012.
    35 changes: 35 additions & 0 deletions dirty.js.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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