It's a Meteor compatible DDP client, based on MarsDB. It supports methods, pub/sub and collection operations. It is very similar to Meteor, but it also have some killer features...
Features
- 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
WARNING
It's only a concept until 1.0. Use it for your own risk.
Examples
Basic example
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 http://localhost:3000
.
Configure a client
import Collection from 'marsdb';
import MarsSync from 'marsdb-sync-client';
MarsSync.configure({ url: 'ws://localhost:3000' });
const posts = new Collection('posts');
posts.find(
{author: 'me'},
{sub: ['postsByAuthor', 'me']}
).observe((posts) => {
});
Wait for subscription ready
const posts = new Collection('posts');
posts.find(
{author: 'me'},
{sub: ['postsByAuthor', 'me'], waitReady: true}
).observe((posts) => {
});
Decide when to use cache
const posts = new Collection('posts');
posts.find(
{author: 'me'},
{sub: ['postsByAuthor', 'me'], tryCache: true}
).observe((posts) => {
});
posts.find(
{author: 'not_me'},
{sub: ['postsByAuthor', 'not_me'], tryCache: (posts) => true}
).observe((posts) => {
});
Methods and subscriptions
import MarsSync from 'marsdb-sync-client';
MarsSync.call('myMethod', 1, 2, 3).result().then((res) => {
}).updated().then(() => {
});
MarsSync.apply('myMethod', [1, 2, 3])
const sub = MarsSync.subscribe('myPublisher', 1, 2, '3th arg');
sub.ready().then(() => {
}).stopped().then(() => {
});
sub.stop();
Roadmap
- More examples of usage and tests
- Documentation
Contributing
I'm waiting for your pull requests and issues.
Don't forget to execute gulp lint
before requesting. Accepted only requests without errors.
License
See License