Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #814 from akre54/reuse-model
Browse files Browse the repository at this point in the history
allow a Model or Collection to be composed with reuse
  • Loading branch information
paulmillr committed Jun 17, 2014
2 parents 734c641 + d3a3edf commit ed62579
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/chaplin/composer.coffee
Expand Up @@ -80,7 +80,11 @@ module.exports = class Composer
else
return @_compose name, options: third, compose: ->
# The compose method here just constructs the class.
@item = new second @options
# Model and Collection both take `options` as the second argument.
if second.prototype instanceof Backbone.Model or second.prototype instanceof Backbone.Collection
@item = new second null, @options
else
@item = new second @options

# Render this item if it has a render method and it either
# doesn't have an autoRender property or that autoRender
Expand Down
7 changes: 7 additions & 0 deletions test/spec/composer_spec.coffee
Expand Up @@ -179,6 +179,13 @@ define [

mediator.publish 'dispatcher:dispatch'

it 'should allow a model to be composed with options', ->
mediator.execute 'composer:compose', 'spy', Model, { collection: 2 }

expect(composer.compositions['spy'].item.collection).to.be 2

mediator.publish 'dispatcher:dispatch'

it 'should allow a composition to be composed', ->
spy = sinon.spy()

Expand Down

0 comments on commit ed62579

Please sign in to comment.