v0.8.2
Duplicate release of v0.8.1
_prepare
is a hook inside Torso View's that allow you to add new fields to the context returned by the defaultprepare
method without having to overrideprepare
. You can update and add to the context by returning your own context or modify the context passed in to_prepare
. Both options will mix the resulting context into the View's default prepare context (taking precedence, overriding the default keys ofmodel
andview
if you choose to use them). It also will override any keys defined byprepareFields
Example:
_prepare: function(context) {
context.foo = 'bar';
}
or
_prepare: function(context) {
return {
foo: 'bar'
}
}
Will result in a context:
{
model: this.model.toJSON(),
view: this.viewState.toJSON(),
foo: 'bar'
}
during a render.
- Added
has
andunset
to Torso View's which alias toviewState.has
andviewState.unset
prepareFields
now can be written as an object (or function who returns an object) whose keys and values will get added to theprepare
's context. This extends the existing behavior of definingprepareFields
as an array (or a function that returns an array) whose values are {key: 'foo', value: bar}.
prepareFields: {
service: myServiceCell,
count: 4
}
Will result in a context:
{
model: this.model.toJSON(),
view: this.viewState.toJSON(),
service: myServiceCell.toJSON(),
count: 4
}
during a render