Sha256: 8c9b5cc9525c0ec565fddc55283c01281463fd476581c51d7d3402ad4492797a

Contents?: true

Size: 950 Bytes

Versions: 14

Compression:

Stored size: 950 Bytes

Contents

class Lanes.Views.ModelObserver extends Lanes.Models.State

    modelEvents: {}

    constructor: (@view, @keypath='model')->
        super
        @view.on( "change:#{@keypath}", this.rebindModel,   this )
        @view.on( "remove",             this.teardown,      this )
        this.rebindModel()

    getModel: ->
        @cached_model ||= Lanes.u.getPath(@keypath, @view)

    unBindModel: (model)->
        for event, fn of @modelEvents
            model.off(event, this[fn], this )

    bindModel: (model)->
        for event, fn of @modelEvents
            model.on(event, this[fn], this )

    rebindModel: ->
        @cached_model=null
        old_model = @view.previous(@keypath)
        new_model = this.getModel()
        return if old_model == new_model
        this.unBindModel( old_model ) if old_model
        this.bindModel(   new_model ) if new_model

    teardown: ->
        this.unBindModel( model ) if model = this.getModel()

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lanes-0.7.0 client/lanes/react/ModelObserver.coffee
lanes-0.6.1 client/lanes/react/ModelObserver.coffee
lanes-0.6.0 client/lanes/react/ModelObserver.coffee
lanes-0.5.6 client/lanes/react/ModelObserver.coffee
lanes-0.5.5 client/lanes/react/ModelObserver.coffee
lanes-0.5.0 client/lanes/react/ModelObserver.coffee
lanes-0.4.0 client/lanes/react/ModelObserver.coffee
lanes-0.3.0 client/lanes/react/ModelObserver.coffee
lanes-0.1.9.5 client/lanes/react/ModelObserver.coffee
lanes-0.1.9 client/lanes/views/ModelObserver.coffee
lanes-0.1.8 client/lanes/views/ModelObserver.coffee
lanes-0.1.7 client/lanes/views/ModelObserver.coffee
lanes-0.1.6 client/lanes/views/ModelObserver.coffee
lanes-0.1.5 client/lanes/views/ModelObserver.coffee