-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(mvc.Collection): add docs and testing for updated collection met… (
- Loading branch information
1 parent
bffa2c0
commit 0e6d464
Showing
12 changed files
with
163 additions
and
20 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/each.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<pre class="docs-method-signature"><code>collection.each(fn, [context])</code></pre> | ||
|
||
<p> | ||
Iterate over models of a collection, and invoke <code>fn</code> for each model. <code>fn</code> is invoked with 3 arguments: | ||
<i>(model, index, array)</i>. | ||
</p> | ||
|
||
<pre><code>const a = new mvc.Model({ id: 1, label: 'a' }); | ||
const b = new mvc.Model({ id: 2, label: 'b' }); | ||
const c = new mvc.Model({ id: 3, label: 'c' }); | ||
const col = new mvc.Collection([a, b, c]); | ||
|
||
col.each((model, i) => model.set({ customData: i })); | ||
|
||
col.each((model) => console.log(model.get('customData'))); | ||
// 0 | ||
// 1 | ||
// 2 | ||
</code></pre> |
15 changes: 15 additions & 0 deletions
15
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/filter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<pre class="docs-method-signature"><code>collection.filter(fn, [context])</code></pre> | ||
|
||
<p> | ||
Iterate over models of a collection, returning an array of all models <code>fn</code> returns truthy for. <code>fn</code> is invoked with three | ||
arguments: <i>(model, index, array)</i>. | ||
</p> | ||
|
||
<pre><code>const a = new mvc.Model({ id: 3, label: 'a' }); | ||
const b = new mvc.Model({ id: 2, label: 'b' }); | ||
const c = new mvc.Model({ id: 1, label: 'c' }); | ||
const d = new mvc.Model({ id: 0, label: 'd' }); | ||
const col = new mvc.Collection([a, b, c, d]); | ||
|
||
console.log(col.filter((model) => model.get('id') === 0).length); // 1 | ||
</code></pre> |
5 changes: 5 additions & 0 deletions
5
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/first.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<pre class="docs-method-signature"><code>collection.first()</code></pre> | ||
|
||
<p> | ||
Return the first model of a collection. | ||
</p> |
15 changes: 15 additions & 0 deletions
15
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/includes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<pre class="docs-method-signature"><code>collection.includes(value)</code></pre> | ||
|
||
<p> | ||
Return <code>true</code> if model is found in a collection. | ||
</p> | ||
|
||
<pre><code>const a = new mvc.Model({ id: 3, label: 'a' }); | ||
const b = new mvc.Model({ id: 2, label: 'b' }); | ||
const c = new mvc.Model({ id: 1, label: 'c' }); | ||
const d = new mvc.Model({ id: 0, label: 'd' }); | ||
const col = new mvc.Collection([a, b, c]); | ||
|
||
console.log(col.includes(a)); // true | ||
console.log(col.includes(d)); // false | ||
</code></pre> |
14 changes: 14 additions & 0 deletions
14
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/isEmpty.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<pre class="docs-method-signature"><code>collection.isEmpty()</code></pre> | ||
|
||
<p> | ||
Return <code>true</code> if a collection is empty. | ||
</p> | ||
|
||
<pre><code>const col = new mvc.Collection([]); | ||
|
||
console.log(col.isEmpty()); // true | ||
|
||
col.set([new mvc.Model({ id: 1, label: 'a' })]); | ||
|
||
console.log(col.isEmpty()); // false | ||
</code></pre> |
5 changes: 5 additions & 0 deletions
5
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/last.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<pre class="docs-method-signature"><code>collection.last()</code></pre> | ||
|
||
<p> | ||
Return the last model of a collection. | ||
</p> |
15 changes: 15 additions & 0 deletions
15
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/map.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<pre class="docs-method-signature"><code>collection.map(fn, [context])</code></pre> | ||
|
||
<p> | ||
Create an array of values by running each model in the collection through <code>fn</code>. <code>fn</code> is invoked with three arguments: | ||
<i>(model, index, array)</i>. | ||
</p> | ||
|
||
<pre><code>const a = new mvc.Model({ id: 3, label: 'a' }); | ||
const b = new mvc.Model({ id: 2, label: 'b' }); | ||
const c = new mvc.Model({ id: 1, label: 'c' }); | ||
const d = new mvc.Model({ id: 0, label: 'd' }); | ||
const col = new mvc.Collection([a, b, c, d]); | ||
|
||
console.log(col.map((model) => model.get('label')).join(' ')); // 'a b c d' | ||
</code></pre> |
17 changes: 0 additions & 17 deletions
17
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/pluck.html
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
packages/joint-core/docs/src/joint/api/mvc/Collection/prototype/reduce.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<pre class="docs-method-signature"><code>collection.reduce(fn, [initialValue])</code></pre> | ||
|
||
<p> | ||
Reduce a collection to a value which is the accumulated result of running each model in the collection through <code>fn</code>, where each | ||
successive invocation is supplied the return value of the previous. If <code>initialValue</code> is not given, the first model in the collection | ||
is used as the initial value. <code>fn</code> is invoked with four arguments: <i>(accumulator, currentValue, currentIndex, array)</i>. | ||
</p> | ||
|
||
<pre><code>const collection = new mvc.Collection([new mvc.Model({ id: 1, label: 'a' })]); | ||
|
||
console.log(collection.reduce((acc, model) => acc.get('id') + model.id )); // 2 | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters