hoodiehq/hoodie.js — pull request #164 by alanshaw (2013-11-07 00:14:34+00:00)
Title: Memory store

More to open the discussion than anything else.

I needed an in memory store for the [hoodie blackboard](https://github.com/alanshaw/hoodie-blackboard). It's using [punk](https://npmjs.org/package/hoodie-plugin-punk) and [reactive](https://npmjs.org/package/hoodie-plugin-reactive).

- Punk is just a remote store that anyone can write to
- Reactive uses store `change` events to run and re-run computations. In this case when a line is inserted into the database, the canvas is wiped and all the lines redrawn.

Relying on `change` events from the punk remote is too latent when drawing - I need stuff to appear straight away, and get sync'd in the background. `local_store.js` is tied to localStorage and only visible to the current user, not everyone so no good if you want to draw together.

I'm using all these things here (should be reasonably self explanatory):
https://github.com/alanshaw/hoodie-blackboard/blob/master/www/js/main.js#L7-L10

`memory_store.js` is essentially `local_store.js` without the localStorage bits. I guess it could be done better. If you pass it a `remote` option it'll sync with that remote store, after you call `subscribeToOutsideEvents`. In the blackboard example I'm creating a in memory store called "punk" with syncs with the `hoodie.punk` remote.

`memory_open.js` is similar to `open.js` but it opens a memory store and attaches itself to `hoodie.memory.open`.

So really, if this gets merged I'd be looking to have punk create its own memory store, but I thought it would be beneficial for other plugin authors to do the same or for app developers to create memory stores that don't get sync'd to a remote.