You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/chapters/collection.md
+1-158Lines changed: 1 addition & 158 deletions
Original file line number
Diff line number
Diff line change
@@ -112,12 +112,6 @@ var tabs = new TabSet([tab1, tab2, tab3]);
112
112
113
113
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.
114
114
115
-
### collection.createSubset( records?, options? )
116
-
117
-
Create a non-aggregating serializable collection which is the subset of the given collection. Takes the same arguments as the collection's constructor.
118
-
119
-
<asideclass="notice">Records in the collection must have an `id` attribute populated to work properly with subsets.</aside>
Execute the sequence of updates in `fun` function in the scope of the transaction.
271
-
272
-
All collection updates occurs in the scope of transactions. Transaction is the sequence of changes which results in a single `changes` event.
273
-
274
-
Transaction can be opened either manually or implicitly with calling any of collection update methods.
275
-
Any additional changes made to the collection or its items in event handlers will be executed in the scope of the original transaction, and won't trigger an additional `changes` events.
276
-
277
-
### collection.updateEach( iteratee : ( val : Record, index ) => void, context? )
278
-
279
-
Similar to the `collection.each`, but wraps an iteration in a transaction. The single `changes` event will be emitted for the group of changes to the records made in `updateEach`.
280
-
281
262
### collection.sort( options? )
282
263
283
264
Force a collection to re-sort itself. You don't need to call this under normal circumstances, as a collection with a comparator will sort itself whenever a record is added. To disable sorting when adding a record, pass `{sort: false}` to add. Calling sort triggers a "sort" event on the collection.
@@ -294,142 +275,4 @@ Remove and return the last record from a collection. Takes the same options as r
294
275
Add a record at the beginning of a collection. Takes the same options as add.
295
276
296
277
### collection.shift( options? )
297
-
Remove and return the first record from a collection. Takes the same options as remove.
298
-
299
-
## Change events
300
-
301
-
All changes in the records cause change events in the collections they are contained in.
302
-
303
-
Subset collections is an exception; they don't observe changes of its elements by default.
When a record inside of the collection is changed.
342
-
343
-
## Serialization
344
-
345
-
All kinds of collections except `Collection.Refs` are serializable.
346
-
347
-
### collection.toJSON()
348
-
349
-
Produces the JSON for the given collection:
350
-
351
-
-`[ { record json }, ... ]` - array of objects for regular aggregating collection.
352
-
-`[ id1, id2, ... ]` - array of record ids for the subset collection.
353
-
354
-
<asideclass="warning">Although the direct call to <code>toJSON()</code> will produce the correct JSON for the <code>Collection.Refs</code>, it cannot be restored from JSON properly. Therefore, records attributes of the <code>Collection.Refs</code> type are not serialized by default. </aside>
355
-
356
-
May be overridden in the particular record or collection class to customize the JSON representation.
357
-
358
-
```javascript
359
-
@define classCommentextendsRecord {
360
-
static attributes = {
361
-
body :''
362
-
}
363
-
}
364
-
365
-
@define classBlogPostextendsRecord {
366
-
static attributes = {
367
-
title :'',
368
-
body :'',
369
-
comments :Comment.Collection
370
-
}
371
-
}
372
-
373
-
constpost=newBlogPost({
374
-
title:"Type-R is cool!",
375
-
comments : [ { body :"Agree" }]
376
-
});
377
-
378
-
constrawJSON=post.toJSON()
379
-
// { title : "Type-R is cool!", body : "", comments : [{ body : "Agree" }] }
380
-
```
381
-
382
-
### `options` { parse : true }
383
-
384
-
Parse raw JSON when passed as an option to the collection's constructor or update methods.
385
-
386
-
### `callback` collection.parse( json )
387
-
388
-
Invoked internally when `{ parse : true }` is passed. May be overridden to define custom JSON transformation. Should not be called explicitly.
389
-
390
-
## Validation
391
-
392
-
Validation happens transparently on the first access to any part of the validation API. Validation results are cached. Only the changed parts of aggregation tree will be validated again.
393
-
394
-
### `callback` collection.validate()
395
-
396
-
Override in the collection subclass to add collection-level validation. Whatever is returned from `validate()` is treated as an error message and triggers the validation error.
397
-
398
-
<asideclass="notice">Do not call this method directly, that's not the way how validation works.</aside>
399
-
400
-
### collection.isValid()
401
-
402
-
Returns `true` if the collection is valid. Similar to `!collection.validationError`.
403
-
404
-
### collection.isValid( recordId )
405
-
406
-
Returns `true` whenever the record from the collection is valid.
407
-
408
-
### record.validationError
409
-
410
-
`null` if the collection is valid, or the detailed information on validation errors.
411
-
412
-
- Aggregating collection is valid whenever `collection.validate()` returns `undefined`_and_ all of its records are valid.
413
-
- Non-aggregating collections are valid whenever `collection.validate()` returns `undefined`.
414
-
415
-
```javascript
416
-
// ValidationError object shape
417
-
{
418
-
error :/* collection-level validation error msg as returned from collection.validate() */,
419
-
420
-
// Collection items validation errors
421
-
nested : {
422
-
// Contains nested ValidationError object for nested records...
423
-
/* record.cid */:/* record.validationError */
424
-
}
425
-
}
426
-
```
427
-
428
-
### collection.getValidationError( recordId )
429
-
430
-
Return the validation error for the given collection's item.
0 commit comments