TodoList
Extends:
This module defines a Backbone.Collection
which stores todos Items
and provides utility methods to filter, sort,
and retrieve the next order number used to sort Items
. Instead of exporting the class itself an instance of the
the class is exported. This allows the instance to be imported anywhere access to the collection is necessary.
Multiple views may access this instance, but in this demo only ManageTodosView
displays data from the collection.
Member Summary
Public Members | ||
public get |
localStorage: *: * Reference to this collection's local storage. |
|
public get |
Reference to this collection's model. |
Method Summary
Public Methods | ||
public |
comparator(item: Item): number Todos are sorted by their original insertion order. |
|
public |
done(): * Filter down the list of all todos items that are finished. |
|
public |
We keep the todos Items in sequential order, despite being saved by unordered GUID in the database. |
|
public |
remaining(): * Filter down the list to only todos items that are still not finished. |
Inherited Summary
From class Events | ||
public |
bind(): * Delegates to |
|
public |
Tell an object to listen to a particular event on an other object. |
|
public |
listenToOnce(obj: object, name: string, callback: function): Events Just like |
|
public |
Remove a previously-bound callback function from an object. |
|
public |
Bind a callback function to an object. |
|
public |
Just like |
|
public |
stopListening(obj: object, name: string, callback: function): Events Tell an object to stop listening to events. |
|
public |
Trigger callbacks for the given event, or space-delimited list of events. |
|
public |
unbind(): * Delegates to |
From class Collection | ||
public |
A comparator string indicating the attribute to sort. |
|
public |
The length of the models array. |
|
public |
The default Backbone.Model class to use as a prototype for this collection. |
|
public |
An array of models in the collection. |
|
public |
Add a model (or an array of models) to the collection, firing an "add" event for each model, and an "update" event afterwards. |
|
public |
Get a model from a collection, specified by index. |
|
public |
clone(): Collection Returns a new instance of the collection with an identical list of models. |
|
public |
Convenience to create a new instance of a model within a collection. |
|
public |
Fetch the default set of models for this collection from the server, setting them on the collection when they arrive. |
|
public |
Just like |
|
public |
Get a model from a collection, specified by an id, a cid, or by passing in a model. |
|
public abstract |
Initialize is an empty function by default. |
|
public |
Override this method to specify the attribute the collection will use to refer to its models in collection.get. |
|
public |
|
|
public |
Pluck an attribute from each model in the collection. |
|
public |
Remove and return the last model from a collection. |
|
public |
Add a model at the end of a collection. |
|
public |
Remove a model (or an array of models) from the collection, and return them. |
|
public |
Adding and removing models one at a time is all well and good, but sometimes you have so many models to change that you'd rather just update the collection in bulk. Use reset to replace a collection with a new list of models (or attribute hashes), triggering a single "reset" event at the end. Returns the newly-set models. For convenience, within a "reset" event, the list of any previous models is available as options.previousModels. Pass null for models to empty your Collection with options. Calling collection.reset() without passing any models as arguments will empty the entire collection. Here's an example using reset to bootstrap a collection during initial page load, in a Rails application: |
|
public |
The set method performs a "smart" update of the collection with the passed list of models. |
|
public |
Remove and return the first model from a collection. |
|
public |
slice(): * Return a shallow copy of this collection's models, using the same options as native |
|
public |
sort(options: object): Collection Force a collection to re-sort itself. |
|
public |
sync(): * Uses Backbone.sync to persist the state of a collection to the server. |
|
public |
Return an array containing the attributes hash of each model (via toJSON) in the collection. |
|
public |
Add a model at the beginning of a collection. |
|
public |
Return an array of all the models in a collection that match the passed attributes. |
|
protected |
_prepareModel(attrs: object, options: object): * Prepare a hash of attributes (or other model) to be added to this collection. |
|
protected |
_reset() Resets all internal state. |
Public Members
Public Methods
public comparator(item: Item): number source
Todos are sorted by their original insertion order.
Override:
Collection#comparatorParams:
Name | Type | Attribute | Description |
item | Item | item model. |
public nextOrder(): number source
We keep the todos Items in sequential order, despite being saved by unordered GUID in the database. This generates the next order number for new items.
public remaining(): * source
Filter down the list to only todos items that are still not finished.
Return:
* |