- Cache collections – with LocalForage, for example
- Auto subcribe/unsubscribe - see examples
- Smart subscriptions – any subscription will be stopped only after 15 sec delay.
- Framework agnostic
- Works in any JS environment – browser, Node.JS, Electron, NW.js, Cordova
It's only a concept until 1.0. Use it for your own risk.
The repository comes with a simple example. To try it out:
git clone https://github.com/c58/marsdb-sync-client.git cd marsdb-sync-client/example && npm install npm start
Then, just point your browser at
Usage with Meteor server and LocalForage
marsdb-sync-client is a DDP client, so it should work well with Meteor server.
But it have an extension for syncing local cache with a server side. The extension is
marsdb-sync-server and is follow:
- Each collection have additional server method called
- This method invoked by MarsSync client on init stage for each collection
- Method invoked with one argument: list of all available document ids in a local cache
- Method must return a sublist of given ids that is NOT presented in a server anymore (deleted ids).
You should implement it by yourself for each collection in Meteor's server-side code. In the future it might be a package for Meteor (it would be great if you implement it).
Example of a sync method for some collection:
// /server/collections/Posts.jsPosts = 'posts';Meteor;
Configure a client
;;// Setup marsdb-sync-clientMarsSync;// User your collectionsconst posts = 'posts';const observer = posts;// When you stop all observers of a cursor// subscription will be automatically stopped// (after 15 sec for optimal client/server communication)observer;
Wait for subscription ready
// Sometimes you need to show a result only when// all documents of a subscription received.// There is special options "waitReady" for this.const posts = 'posts';posts;
Decide when to use cache
// Cache is good, but sometimes you need to decide when to use// cache, and when to wait new data from the server...const posts = 'posts';posts;posts;
Methods and subscriptions
;MarsSync;// Similar for "apply"MarsSync// You can also subscribe just like in Meteorconst sub = MarsSync;sub;// Stop the subscriptionsub;
- More examples of usage and tests
I'm waiting for your pull requests and issues.
Don't forget to execute
gulp lint before requesting. Accepted only requests without errors.