Models, Stores and Lists

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.

Swick.Model

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).

Swick.Store

Store is an unordered collection of Models, 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.

Swick.List

List is also a collection of Models, 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.