Another feature that was inspired by Backbone is state management. Model
in Swick is very similar to Model
in Backbone. However, instead of Collection
there're two separate entities: Store
and List
.
Model
is basically just a wrapped JavaScript object, which triggers change
events whenever any field in it changes. For performance reasons, to perform such update, you need to call set
method on it: you must not change values directly (which are available under value
field).
Store
is an unordered collection of Model
s, it's a key-value storage (a map). Internally it's similar to a Model
where each field contains another Model
. By default, it uses id
field as keys (but you can override idAt
method to change this behavior). When creating a Store
you can specify the subclass of Model
which will be used to wrap each value in this store.
List
is also a collection of Model
s, but it's ordered (like an array). Instead of actually storing Models, it can be linked to a Store
and contain only identifiers of its items.