Meteor + Redux — storing your Collections in a stateful manner

If you want to use Meteor + Redux, then you can store your collection data inside an immutable data object, kept up to date with all DB changes that your subscription can receive.

This can be done by using the Collection class’ built-in observeChanges() method (on the client) and putting the data returned by the add/change/remove events fired into a Redux store.

You won’t be able to query the stored data, but if you store it as an object with each record’s ID as its key, then you can iterate through it and also access individual records directly. The best thing? You don’t need to worry about writing separate Redux actions to call your Meteor Methods for writing to the DB. Just call your Meteor Methods directly — your data store will receive the changed data through observeChanges() and put it where you need it.

Note: expect bugs. This is untested. Any issues and I’ll update the gist.

Like what you read? Give Rich Nicholls a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.