'use strict'
_ = require 'underscore'
Backbone = require 'backbone'
EventBroker = require 'chaplin/lib/event_broker'
has = Object::hasOwnProperty'use strict'
_ = require 'underscore'
Backbone = require 'backbone'
EventBroker = require 'chaplin/lib/event_broker'
has = Object::hasOwnPropertyA utility class that is meant as a simple proxied version of a controller that is used internally to inflate simple calls to !composer:compose and may be extended and used to have complete control over the composition process.
module.exports = class CompositionBorrow the static extend method from Backbone.
@extend = Backbone.Model.extendMixin Backbone events and EventBroker.
_.extend @prototype, Backbone.Events
_.extend @prototype, EventBrokerThe item that is composed; this is by default a reference to this.
item: nullThe options that this composition was constructed with.
options: nullWhether this composition is currently stale.
_stale: false
constructor: (options) ->
@options = _.extend {}, options if options?
@item = this
@initialize @options
initialize: -> compose: ->Empty per default.
The check method is called when this composition is asked to be composed again. The passed options are the newly passed options. If this returns false then the composition is re-composed.
check: (options) ->
_.isEqual @options, optionsMarks all applicable items as stale.
stale: (value) ->Return the current property if not requesting a change.
return @_stale unless value?Sets the stale property for every item in the composition that has it.
@_stale = value
for name, item of this when (
item and item isnt this and
typeof item is 'object' and has.call(item, 'stale')
)
item.stale = valueReturn nothing.
return disposed: false
dispose: ->
return if @disposedDispose and delete all members which are disposable.
for own prop, obj of this when obj and typeof obj.dispose is 'function'
unless obj is this
obj.dispose()
delete this[prop]Unbind handlers of global events.
@unsubscribeAllEvents()Unbind all referenced handlers.
@stopListening()Remove properties which are not disposable.
properties = ['redirected']
delete this[prop] for prop in propertiesFinished.
@disposed = trueYou're frozen when your heart’s not open.
Object.freeze? this