Skip to content

Commit 5b6ec65

Browse files
author
Vlad Balin
committed
New I/O docs
1 parent aeaeea0 commit 5b6ec65

File tree

10 files changed

+2161
-1349
lines changed

10 files changed

+2161
-1349
lines changed

docs/chapters/collection.md

Lines changed: 1 addition & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ var tabs = new TabSet([tab1, tab2, tab3]);
112112

113113
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.
114114

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-
<aside class="notice">Records in the collection must have an `id` attribute populated to work properly with subsets.</aside>
120-
121115
### `callback` collection.initialize( records?, options? )
122116

123117
Initialization function which is called at the end of the constructor.
@@ -265,19 +259,6 @@ Calling `collection.reset()` without passing any records as arguments will empty
265259
1. Trigger event `reset`( collection, options ).
266260
2. Trigger event `changes`( collection, options ).
267261

268-
### collection.transaction( fun )
269-
270-
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-
281262
### collection.sort( options? )
282263

283264
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
294275
Add a record at the beginning of a collection. Takes the same options as add.
295276

296277
### 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.
304-
305-
### Events mixin methods (7)
306-
307-
Collection implements [Events](#events-mixin) mixin.
308-
309-
### `static` itemEvents = { eventName : `handler`, ... }
310-
311-
Subscribe for events from records. The `hander` is either the collection's method name, the handler function, or `true`.
312-
313-
When `true` is passed as a handler, the corresponding event will be triggered on the collection.
314-
315-
### `event` "changes" (collection, options)
316-
317-
When collection has changed. Single event triggered when the collection has been changed.
318-
319-
### `event` "reset" (collection, options)
320-
321-
When the collection's entire contents have been reset (`reset()` method was called).
322-
323-
### `event` "update" (collection, options)
324-
325-
Single event triggered after any number of records have been added or removed from a collection.
326-
327-
### `event` "sort" (collection, options)
328-
329-
When the collection has been re-sorted.
330-
331-
### `event` "add" (record, collection, options)
332-
333-
When a record is added to a collection.
334-
335-
### `event` "remove" (record, collection, options)
336-
337-
When a record is removed from a collection.
338-
339-
### `event` "change" (record, options)
340-
341-
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-
<aside class="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 class Comment extends Record {
360-
static attributes = {
361-
body : ''
362-
}
363-
}
364-
365-
@define class BlogPost extends Record {
366-
static attributes = {
367-
title : '',
368-
body : '',
369-
comments : Comment.Collection
370-
}
371-
}
372-
373-
const post = new BlogPost({
374-
title: "Type-R is cool!",
375-
comments : [ { body : "Agree" }]
376-
});
377-
378-
const rawJSON = 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-
<aside class="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.
431-
432-
### collection.eachValidationError( iteratee : ( error, key, recordOrCollection ) => void )
433-
434-
Recursively traverse aggregation tree errors. `key` is `null` for the record-level validation error (returned from `validate()`).
435-
`recordOrCollection` is the reference to the current object.
278+
Remove and return the first record from a collection. Takes the same options as remove.

0 commit comments

Comments
 (0)