Skip to content

JavaScript client library to connect to a remoteStorage server.

Notifications You must be signed in to change notification settings

nunoar/remotestorage.js

 
 

Repository files navigation

remoteStorage.js

Build Status

Where to get help?

Adding remotestorage.js v0.7.2 to your app:

<script src="remotestorage.min.js"></script>
<!-- the modules can be found in the modules repository: https://github.com/remotestorage/modules -->
<script src="remotestorage-contacts.js"></script>
  • claim access to the 'pictures' module, and display the widget:
remoteStorage.claimAccess({ contacts: 'rw' })
remoteStorage.displayWidget();
  • if your app can only be used while connected, then add this:
remoteStorage.on('ready', function() {
  showApp();
});
remoteStorage.on('disconnect', function() {
  hideApp();
});
  • in any case, update the DOM when changes come in (this is module specific):
remoteStorage.contacts.on('change', function(event) {
  // handle change event
  event.origin; // -> "tab", "device" or "remote"
  event.path; // /contacts/card/... (absolute path)
  event.relativePath; // card/... (relative to the module root, i.e. /contacts/)
  event.oldValue; // the previous value stored at the path (or 'undefined', if there was no previous value)
  event.newValue; // the curretn value stored at the path (or 'undefined', if the change was a deletion)
});
  • to handle conflicting changes, install a "conflict" handler as well (if you don't do this, changes on the server will win over local changes):
remoteStorage.contacts.on('conflict', function(event) {
  // you have the following attributes:
  event.path;
  event.localValue;
  event.remoteValue;
  event.type; // either "delete" or "merge"
  // to resolve the conflict, call 'event.resolve' either now or in the future:
  event.resolve('local'); // take local version
  // OR
  event.resolve('remote'); // take remote version
});

see example/minimal-0.7.0/index.html for a full example code.

Running the local Test Server

To test remoteStorage enabled apps, you need to have a remoteStorage compatible storage account. To find out how to get one, see Get Storage on remotestorage.io.

Additionally, remoteStorage.js brings a tiny example server for nodeJS.

  • To run the test server, first of all add a line

    127.0.0.1 local.dev

  • to your /etc/hosts file. then run:

    sudo node server/nodejs-example.js

  • You can then connect as "[email protected]"

About

JavaScript client library to connect to a remoteStorage server.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%