Sha256: e11c1fbff76ecab22b31d558950edc75c9d9bd77a48d7b4f8e3ab6a36c598392

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

# ------------------------------------------------------------------ #
# The ModelChangeMonitor watches for changes on the                  #
# Model and remembers which attributes have been changed             #
# ------------------------------------------------------------------ #
class Lanes.Models.ChangeMonitor
    constructor: (@model)->
        @model.on('change', this.onChange, this)

    onChange: (record,options)->
        attrs = @model.changedAttributes()
        this.recordChanged( _.keys(attrs) )

    recordChanged: (names)->
        @_unsaved ||= {}
        for name in names
            this.recordChangedAttribute(name)

    changedAttributes: ->
        _.keys(@_unsaved)

    recordChangedAttribute:(name)->
        if @model._definition[name] && !@model._definition[name].session
            @_unsaved[ name ] = true

    reset: ->
        delete @_unsaved

    isDirty: ->
        !_.isEmpty(@_unsaved)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lanes-0.1.5 client/lanes/models/ChangeMonitor.coffee