Skip to content

Commit a2f3147

Browse files
author
Vlad Balin
committed
docs
1 parent db9895f commit a2f3147

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

docs/chapters/collection.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Collection
22

3-
Collections are ordered sets of records. You can bind "changes" events to be notified when the collection has been modified, listen for "add" and "remove" events, fetch the collection from the server, and use a full suite of iteration methods.
3+
Collections are ordered sets of records. You can bind "changes" events to be notified when the collection has been modified, listen for the record "add", "remove", and "change" events, and use a full suite of iteration methods.
44

55
```javascript
66
// Implicitly defined collection.
@@ -51,27 +51,37 @@ Specify the record type inside of the collection's definition. This property is
5151

5252
## Create and dispose
5353

54-
### new Collection()
54+
### new Collection( records?, options? )
5555

56-
Create an empty collection.
57-
58-
### new Collection( records, options? )
56+
Create an aggregating serializable collection of records. The collection will take an ownership on its records and will put an error in the console if it can't.
5957

6058
When creating a Collection, you may choose to pass in the initial array of records. The collection's comparator may be included as an option. Passing `false` as the comparator option will prevent sorting. If you define an `initialize() ` function, it will be invoked when the collection is created.
6159

6260
```javascript
6361
var tabs = new TabSet([tab1, tab2, tab3]);
6462
```
6563

66-
### collection.initialize( records?, options? )
64+
### new Collection.Refs( records?, options? )
6765

68-
Initialization function which is called at the end of the constructor.
66+
Create a non-aggregating non-serializable collection. The collection does not take ownership in its records. In all other aspects it behaves as the regular collection.
6967

70-
### collection.dispose()
68+
### collection.createSubset( records?, options? )
69+
70+
Create a non-aggregating serializable collection which is the subset of the given collection. Takes the same arguments as the collection's constructor.
71+
72+
<aside class="notice">Records in the collection must have an `id` attribute populated to work properly with subsets.</aside>
73+
74+
### `callback` collection.initialize( records?, options? )
75+
76+
Initialization function which is called at the end of the constructor.
7177

7278
### collection.clone()
7379

74-
### collection.createSubset()
80+
Clone the collection. Aggregating collection will be recursively cloned, non-aggregated collections will be shallow cloned.
81+
82+
### collection.dispose()
83+
84+
Dispose the collection. Aggregating collection will recursively dispose its records.
7585

7686
## Read and iterate
7787

@@ -193,6 +203,12 @@ vanHalen.set([ eddie, alex, stone, hagar ]);
193203
// changed over the years.
194204
```
195205

206+
### collection.assignFrom( otherCollection )
207+
208+
Synchronize the state of the collection and its aggregation tree with other collection of the same type. Updates existing objects in place. Record in the collection is considered to be "existing" if it has the same `id`.
209+
210+
Equivalent to `collection.set( otherCollection.models, { merge : true } )` and triggers similar events on change.
211+
196212
### collection.reset( records, options? )
197213

198214
Replace the collection's content with the new records. More efficient than `collection.set`, but does not send record-level events.

docs/index.html

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ <h3 id="record-eachvalidationerror-iteratee-error-key-recordorcollection-void-">
824824
<p>Recursively traverse aggregation tree errors. <code>key</code> is <code>null</code> for the record-level validation error (returned from <code>validate()</code>).
825825
<code>recordOrCollection</code> is the reference to the current object.</p>
826826
<h1 id="collection">Collection</h1>
827-
<p>Collections are ordered sets of records. You can bind &quot;changes&quot; events to be notified when the collection has been modified, listen for &quot;add&quot; and &quot;remove&quot; events, fetch the collection from the server, and use a full suite of iteration methods.</p>
827+
<p>Collections are ordered sets of records. You can bind &quot;changes&quot; events to be notified when the collection has been modified, listen for the record &quot;add&quot;, &quot;remove&quot;, and &quot;change&quot; events, and use a full suite of iteration methods.</p>
828828
<pre><code class="highlight javascript"><span class="hljs-comment">// Implicitly defined collection.</span>
829829
<span class="hljs-keyword">const</span> books = <span class="hljs-keyword">new</span> Book.Collection();
830830

@@ -861,17 +861,23 @@ <h3 id="-static-model-recordconstructor"><code>static</code> model = RecordConst
861861
}
862862
</code></pre>
863863
<h2 id="create-and-dispose">Create and dispose</h2>
864-
<h3 id="new-collection-">new Collection()</h3>
865-
<p>Create an empty collection.</p>
866-
<h3 id="new-collection-records-options-">new Collection( records, options? )</h3>
864+
<h3 id="new-collection-records-options-">new Collection( records?, options? )</h3>
865+
<p>Create an aggregating serializable collection of records. The collection will take an ownership on its records and will put an error in the console if it can&#39;t.</p>
867866
<p>When creating a Collection, you may choose to pass in the initial array of records. The collection&#39;s comparator may be included as an option. Passing <code>false</code> as the comparator option will prevent sorting. If you define an <code>initialize()</code> function, it will be invoked when the collection is created.</p>
868867
<pre><code class="highlight javascript"><span class="hljs-keyword">var</span> tabs = <span class="hljs-keyword">new</span> TabSet([tab1, tab2, tab3]);
869868
</code></pre>
870-
<h3 id="collection-initialize-records-options-">collection.initialize( records?, options? )</h3>
869+
<h3 id="new-collection-refs-records-options-">new Collection.Refs( records?, options? )</h3>
870+
<p>Create a non-aggregating non-serializable collection. The collection does not take ownership in its records. In all other aspects it behaves as the regular collection.</p>
871+
<h3 id="collection-createsubset-records-options-">collection.createSubset( records?, options? )</h3>
872+
<p>Create a non-aggregating serializable collection which is the subset of the given collection. Takes the same arguments as the collection&#39;s constructor.</p>
873+
<aside class="notice">Records in the collection must have an `id` attribute populated to work properly with subsets.</aside>
874+
875+
<h3 id="-callback-collection-initialize-records-options-"><code>callback</code> collection.initialize( records?, options? )</h3>
871876
<p>Initialization function which is called at the end of the constructor.</p>
872-
<h3 id="collection-dispose-">collection.dispose()</h3>
873877
<h3 id="collection-clone-">collection.clone()</h3>
874-
<h3 id="collection-createsubset-">collection.createSubset()</h3>
878+
<p>Clone the collection. Aggregating collection will be recursively cloned, non-aggregated collections will be shallow cloned.</p>
879+
<h3 id="collection-dispose-">collection.dispose()</h3>
880+
<p>Dispose the collection. Aggregating collection will recursively dispose its records.</p>
875881
<h2 id="read-and-iterate">Read and iterate</h2>
876882
<h3 id="collection-get-id-">collection.get( id )</h3>
877883
<p>Get a record from a collection, specified by an <code>id</code>, a <code>cid</code>, or by passing in a record.</p>
@@ -964,6 +970,9 @@ <h4 id="events">Events</h4>
964970
<span class="hljs-comment">// Updates any of stone, alex, and eddie's attributes that may have</span>
965971
<span class="hljs-comment">// changed over the years.</span>
966972
</code></pre>
973+
<h3 id="collection-assignfrom-othercollection-">collection.assignFrom( otherCollection )</h3>
974+
<p>Synchronize the state of the collection and its aggregation tree with other collection of the same type. Updates existing objects in place. Record in the collection is considered to be &quot;existing&quot; if it has the same <code>id</code>.</p>
975+
<p>Equivalent to <code>collection.set( otherCollection.models, { merge : true } )</code> and triggers similar events on change.</p>
967976
<h3 id="collection-reset-records-options-">collection.reset( records, options? )</h3>
968977
<p>Replace the collection&#39;s content with the new records. More efficient than <code>collection.set</code>, but does not send record-level events.</p>
969978
<p>Calling <code>collection.reset()</code> without passing any records as arguments will empty the entire collection.</p>

0 commit comments

Comments
 (0)