Dumb Collections for Meteor, in which the client syncs with server only on demand.
To avoid the livedata overhead associated with the usual pub/sub model, whilst retaining the benefits of minimongo and the Collections API. Also utilises localStorage to improve load times.
NEW IN VERSION 1.1.0
- Now compatible with Collection2.
- Ability to specify
optionsas well as
- Insertion and removal is now far, far more efficient.
reactiveparameter to allow client-side collection to be cleared non-reactively.
MyCollection = new DumbCollection('mycollection');
Note 1 - This relates to the 1.0.0 release of Iron Router - it is untested with previous versions.
Note 2 - If you only want to wait for the collection to be loaded from localStorage rather than being synchronised, just return the collection itself (i.e.
Note 3 - If you want to run the synchronisation from Iron Router hooks, you must do this from the
onRun hook, rather than
data, or any of the other reactive hooks. If you don't then the route will continually reload reactively and the Dumb Collection will try to resynchronise each time. See the demo for an example.
- Synchronisation is always from the server to the client by design, so the user will need to write Meteor.methods with appropriate security to perform CUD in the opposite direction.
updatemethod on the server collection has been renamed
_updatein an attempt to discourage its use - the synchronisation is based on
_ids, and so any
updates made on the server side cannot be synchronised. Given that one cannot update the
_idfield in MongoDB, it is necessary to remove and then insert, and rather than writing a method for this, it has been left to the user to tailor to their use case.
- localStorage is a limited size, and if this is exceeded then no documents will be stored locally, with synchronisation required to populate the collection on the server. The
failCallbackwill be fired in this case.