Sha256: 9ae2b93602ef664a42fe724077e64e043d708f49fd333bbcbea616ae2d2a4465

Contents?: true

Size: 714 Bytes

Versions: 2

Compression:

Stored size: 714 Bytes

Contents

# Luca.Model
#
# Luca.Model is an extenstion of Backbone.Model which provides
# few useful patterns:
#
#   - computed properties support
_.component('Luca.Model').extends('Backbone.Model').with
  initialize: ()->
    Backbone.Model::initialize @, arguments

    return if _.isUndefined(@computed)

    @_computed = {}

    for attr, dependencies of @computed
      @on "change:#{attr}", ()=>
        @_computed[attr] = @[attr].call @

      _(dependencies).each (dep)=>
        @on "change:#{dep}", ()=>
          @trigger "change:#{attr}"
        @trigger "change:#{attr}" if @has(dep)

  get: (attr)->
    if @computed?.hasOwnProperty(attr)
      @_computed[attr]
    else
      Backbone.Model::get.call @, attr

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
luca-0.8.599 src/core/model.coffee
luca-0.8.59 src/core/model.coffee