Skip to content

Commit

Permalink
Add documentation for Collection#mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed May 16, 2017
1 parent 81f5d1a commit 0eca92f
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@
<li data-name="clone"><a href="#Collection-clone">clone</a></li>
<li data-name="fetch"><a href="#Collection-fetch">fetch</a></li>
<li data-name="create"><a href="#Collection-create">create</a></li>
<li data-name="sync"><a href="#Collection-mixin">mixin</a></li>
</ul>
</div>

Expand Down Expand Up @@ -2405,6 +2406,32 @@ <h2 id="Collection">Backbone.Collection</h2>
title: "Othello",
author: "William Shakespeare"
});
</pre>

<p id="Collection-mixin">
<b class="header">mixin</b><code>Backbone.Collection.mixin(properties)</code>
<br />
<code>mixin</code> provides a way to enhance the base <b>Backbone.Collection</b>
and any collections which extend it. This can be used to add generic methods
(e.g. additional <a href="#Collection-Underscore-Methods"><b>Underscore Methods</b></a>).
</p>

<pre>
Backbone.Collection.mixin({
sum: function(models, iteratee) {
return _.reduce(models, function(s, m) {
return s + iteratee(m);
}, 0);
}
});

var cart = new Backbone.Collection([
{price: 16, name: 'monopoly'},
{price: 5, name: 'deck of cards'},
{price: 20, name: 'chess'}
]);

var cost = cart.sum('price');
</pre>

<h2 id="Router">Backbone.Router</h2>
Expand Down Expand Up @@ -4418,19 +4445,19 @@ <h2 id="changelog">Change Log</h2>
Added support for setting instance properties before the constructor in <tt>ES2015 classes</tt> with a <tt>preinitialize</tt> method.
</li>
<li>
Added <tt>iterator</tt> support implementing JS Iterable protocol.
Collections now support the [Javascript Iterator Protocol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Iteration_protocols)
</li>
<li>
Fixed a bug with the Router's hash generator.
`#listenTo` uses the listened object's public `#on` method. This keeps interop between Backbone and other event libraries (including Node.js).
</li>
<li>
`#listenTo` uses the listened object's public `#on` method. This keeps interop between Backbone and any other event library (including Node.js).
<tt>Collection.get</tt> now checks if obj is a <tt>Model</tt> to allow retrieving models with an `attributes` key.
</li>
<li>
<tt>Collection.get</tt> now checks if obj is a <tt>Model</tt> to allow retrieving models with an `attributes` key.
Fixed several issues with Router's URL hashing and parsing.
</li>
<li>
We no longer test against IE8. Now we are not testing for <= IE8, with the goal of eventually refactoring some of the older hacks out.
We are no longer testing for <= IE8, with the goal of eventually refactoring some of the older hacks out.
</li>
</ul>

Expand All @@ -4447,6 +4474,9 @@ <h2 id="changelog">Change Log</h2>
Added <tt>options.changes</tt> to <tt>Collection</tt> "update" event which
includes added, merged, and removed models.
</li>
<li>
Added support for <tt>Collection#mixin</tt> and <tt>Model#mixin</tt>.
</li>
<li>
Ensured <tt>Collection#reduce</tt> and <tt>Collection#reduceRight</tt>
work without an initial <tt>accumulator</tt> value.
Expand Down

1 comment on commit 0eca92f

@megawac
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping #4134 #4028

Please sign in to comment.