Skip to content

Instantly share code, notes, and snippets.

@ritch
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/11094826 to your computer and use it in GitHub Desktop.
Save ritch/11094826 to your computer and use it in GitHub Desktop.
FAQ for LoopBack replication

Will it be possible to use continuous replication, so the client immediately triggers a replication when local data changes. And the server uses a push mechanism?

Yes... here is a basic example that relies on a socket.io style EventEmitter.

// psuedo-server.js
MyModel.on('changed', function(obj) {
  socket.emit('changed');
});

// psuedo-client.js
socket.on('changed', function(obj) {
  LocalModel.replicate(RemoteModel);
});

Is it possible to trigger immediate replication?

Yes. Calling Model.replicate() will trigger an immediate replication.

How are conflicts handled (e.g. an object or field is modified both locally and remotely)?

A conflict occurs when a change to a model is not based on the previous revision of the model.

The callback of Model.replicate() takes err and conflict[]. Each conflict represents a change that was not replicated and must be manually resolved. You can fetch the current versions of the local and remote models by calling conflict.models(). You can manaully merge the conflict by modifying both models. Calling conflict.resolve() will set the source change's previous revision to the current revision of the (conflicting) target change. Since the changes are no longer conflicting and appear as if the source change was based on the target, they will be replicated normally as part of the next replicate() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment