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/Mixins.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# Mixins
2
2
3
-
## Decorators
4
-
5
3
Type-R is based on mixins with configurable properties merge rules.
6
4
5
+
## Definition
6
+
7
7
### `decorator`@mixins( mixinA, mixinB, ... ) class X ...
8
8
9
9
Merge specified mixins to the class definition. Both plain JS object and class constructor may be used as mixin. In the case of the class constructor, missing static members will copied over as well.
Copy file name to clipboardExpand all lines: docs/chapters/collection.md
+63-64Lines changed: 63 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,6 @@
1
1
# Collection
2
2
3
-
Collections are ordered sets of records. You can bind "change" events to be notified when any record in the collection has been modified, listen for "add" and "remove" events, fetch the collection from the server, and use a full suite of Underscore.js methods.
4
-
5
-
Collection is implicitly defined for every record with a constructor accessible as `MyRecord.Collection`. In most cases, you
6
-
don't need to declare it manually.
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.
7
4
8
5
```javascript
9
6
// Implicitly defined collection.
@@ -30,17 +27,19 @@ class Comics extends Book {
30
27
}
31
28
```
32
29
33
-
## Collection definition
30
+
## Definition
31
+
32
+
### RecordClass.Collection
34
33
35
-
### RecordConstructor.Collection
34
+
Default collection constructor for the given Record class.
36
35
37
-
Every `Record` class has implicitly defined Collection, which can be referenced adding the `.Collection` to the record's constructor.
36
+
Collection is implicitly defined for every record with a constructor accessible as `MyRecord.Collection`. In most cases, you don't need to declare it manually.
Replaces implicitly defined collection with externally defined collection class.
40
+
Non-aggregating collection constructor.
42
41
43
-
### (collection definition) `static` model = RecordConstructor
42
+
### `static` model = RecordConstructor
44
43
45
44
Specify the record type inside of the collection's definition. This property is being set automatically for collection types referenced as `MyRecord.Collection`.
46
45
@@ -50,7 +49,7 @@ Specify the record type inside of the collection's definition. This property is
50
49
}
51
50
```
52
51
53
-
## Create and access the collection
52
+
## Create and dispose
54
53
55
54
### new Collection()
56
55
@@ -68,6 +67,19 @@ var tabs = new TabSet([tab1, tab2, tab3]);
68
67
69
68
Initialization function which is called at the end of the constructor.
70
69
70
+
### collection.dispose()
71
+
72
+
### collection.clone()
73
+
74
+
### collection.createSubset()
75
+
76
+
## Read and Update
77
+
78
+
Methods to update the collection. They accept common options:
79
+
80
+
-`sort : false` - do not sort the collection.
81
+
-`parse : true` - parse raw JSON (used to set collection with a data from the server).
82
+
71
83
### collection.get( id )
72
84
Get a record from a collection, specified by an `id`, a `cid`, or by passing in a record.
73
85
@@ -86,13 +98,6 @@ Like an array, a Collection maintains a length property, counting the number of
86
98
87
99
Raw access to the JavaScript array of records inside of the collection. Usually you'll want to use `get`, `at`, or the other methods to access record objects, but occasionally a direct reference to the array is desired.
88
100
89
-
## Updates
90
-
91
-
Methods to update the collection. They accept common options:
92
-
93
-
-`sort : false` - do not sort the collection.
94
-
-`parse : true` - parse raw JSON (used to set collection with a data from the server).
95
-
96
101
### collection.add( records, options? )
97
102
98
103
Add a record (or an array of records) to the collection. If this is the `Record.Collection`, you may also pass raw attributes objects, and have them be vivified as instances of the `Record`. Returns the added (or preexisting, if duplicate) records.
@@ -149,22 +154,44 @@ Calling `collection.reset()` without passing any records as arguments will empty
Execute the sequence of updates in `fun` function in the scope of the transaction.
153
160
154
161
All collection updates occurs in the scope of transactions. Transaction is the sequence of changes which results in a single `changes` event.
155
162
156
163
Transaction can be opened either manually or implicitly with calling any of collection update methods.
157
164
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.
158
165
159
-
### collection.transaction( fun )
160
-
161
-
Execute the sequence of updates in `fun` function in the scope of the transaction.
162
-
163
166
### collection.updateEach( iteratee : ( val : Record, index ) => void, context? )
164
167
165
168
Similar to the `collection.each`, but wraps the loop in a transaction.
166
169
167
-
## Observable changes
170
+
### collection.push( record, options? )
171
+
172
+
Add a record at the end of a collection. Takes the same options as add.
173
+
174
+
### collection.pop( options? )
175
+
Remove and return the last record from a collection. Takes the same options as remove.
176
+
177
+
### collection.unshift( record, options? )
178
+
179
+
Add a record at the beginning of a collection. Takes the same options as add.
180
+
181
+
### collection.shift( options? )
182
+
Remove and return the first record from a collection. Takes the same options as remove.
183
+
184
+
### collection.slice( begin, end )
185
+
186
+
Return a shallow copy of the `collection.models`, using the same options as native Array#slice.
187
+
188
+
### collection.indexOf( recordOrId : any ) : number
189
+
190
+
Return an index of the record in the collection, and -1 if there are no such a record in the collection.
191
+
192
+
Can take the record itself as an argument, `id`, or `cid` of the record.
193
+
194
+
## Change events
168
195
169
196
Object tree formed by nested records is deeply observable by default; changes in every item trigger change events for the collection and all parent elements in sequence.
170
197
@@ -178,31 +205,22 @@ Collection triggers following events on change:
178
205
-`reset`*( collection, options )* if `collection.reset()` was used to update the collection.
179
206
-`changes`*( collection, options )* in case of any changes.
180
207
181
-
## Listening to changes with Events API
182
-
183
-
[Events API](../10_Events.md) is used for managing events subscriptions.
184
-
185
-
### listener.listenTo( record, event, handler )
186
-
187
-
[Events API](../10_Events.md) method used to listen to the any of the change events.
188
-
189
-
### listener.stopListening( record )
190
-
191
-
[Events API](../10_Events.md) method to explicitly stop all event subscriptions from the record.
208
+
### Events mixin methods (7)
192
209
193
-
Not needed if the listener is other record or collection.
@@ -242,6 +258,8 @@ Note that Type-R depends on the arity of your comparator function to determine b
242
258
243
259
Collections with a comparator will not automatically re-sort if you later change record attributes, so you may wish to call sort after changing record attributes that would affect the order.
244
260
261
+
## Sorting
262
+
245
263
### `static` comparator = 'attrName'
246
264
247
265
Maintain the collection in sorted order by the given record's attribute.
@@ -279,26 +297,7 @@ alert(chapters.map( x => x.title ));
279
297
280
298
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.
281
299
282
-
### collection.push( record, options? )
300
+
##Serialization
283
301
284
-
Add a record at the end of a collection. Takes the same options as add.
285
-
286
-
### collection.pop( options? )
287
-
Remove and return the last record from a collection. Takes the same options as remove.
288
-
289
-
### collection.unshift( record, options? )
290
-
291
-
Add a record at the beginning of a collection. Takes the same options as add.
292
-
293
-
### collection.shift( options? )
294
-
Remove and return the first record from a collection. Takes the same options as remove.
295
-
296
-
### collection.slice( begin, end )
297
-
298
-
Return a shallow copy of the `collection.models`, using the same options as native Array#slice.
302
+
## Validation
299
303
300
-
### collection.indexOf( recordOrId : any ) : number
301
-
302
-
Return an index of the record in the collection, and -1 if there are no such a record in the collection.
303
-
304
-
Can take the record itself as an argument, `id`, or `cid` of the record.
0 commit comments