11

With all the buzz around Offline First applications, one of the firsts things that comes up is the data synchronization between the client and the server.

There are several posts and questions about this subject and during my research I found a very interesting "standalone library for data access and synchronization" called Orbit.js.

Until now I could not find any post or question about the integration between Orbit.js and AngularJS, all the reference I found is integrating with Ember.js and Foundation.

I'd like to know if someone has already tried both in the same project.
Is there any limitation/restriction? Orbit.js as the documentation says:

Orbit.js has no specific external run-time dependencies, but must be used with a library that implements the Promises/A+ spec, such as RSVP.

Could this be a restriction for integrating it with AngularJS?

Denis C de Azevedo
  • 6,276
  • 2
  • 32
  • 49
  • 1
    Would be very nice to hear the answers. – Sergey Romanov Oct 07 '14 at 01:51
  • Orbit.js Promise and ajax interfaces differ from AngularJS $q and $http. It may requires some pull requests to make Orbit.js more flexible for such integration. I'm going to use AngularJS + Orbit.js in one my project, because of JSON API implementation of latter. Would be glad to describe results. –  Oct 24 '14 at 18:48
  • @Arantir Good luck Arantir! Share the results here! Thanks – Denis C de Azevedo Oct 25 '14 at 00:08
  • @Arantir I believe that `$q` and `$http` implement the basic spec, as shown in your link. `$http` decorates its promise object with extra methods specific to that service (`success()` and `error()`), and Angular's `$q` service doesn't provide the full functionality of [the real `Q` library](https://github.com/kriskowal/q) - but it should support that A+ spec without any real issues. (This means promises and the `then()` operator.) –  Oct 29 '14 at 15:17
  • 1
    Yes, I've found that `$q` can be used directly, actually. Like this `Orbit.Promise = $q`. It's a standard. But `jQuery.ajax` is not. You could override `OC.JSONAPISource.prototype.ajax` but there is some convenient logic inside. It's also possible to write a custom wrapper to pass to `Orbit.ajax`. But it both ways it will be messy. Though it's enough for beginning, I'm going to simplify ajax dependency in some way if I could. –  Oct 29 '14 at 16:24
  • @Arantir did you have any luck with the implementation? – Mustela Jan 03 '16 at 14:23
  • @Mustela no, unfortunately, we still don't follow offline-first approach and Orbit.js has no application for our current needs. –  Jan 03 '16 at 14:52

1 Answers1

0

The two seem like they might play nice together, but I have not myself put together an application with these two. However, another option is to use a different data sync library. A few months back I stumbled on Pouch DB and it does indeed have an angular module.

Here are the links to do some digging. Hope it helps!

PouchDB - http://pouchdb.com Angular Module - https://github.com/wspringer/angular-pouchdb

Popcorn245
  • 577
  • 6
  • 14
  • 3
    Yeah, definitely it looks like a nice sync lib, however it only works with CouchDB. And this is a huge limitation... – Denis C de Azevedo Nov 02 '14 at 17:27
  • @denisazevedo That's not true. It has CouchDB support baked in, but using the events you could have it make HTTP requests to a REST API like I have done. Hope this helps! ^_^ – Popcorn245 Nov 02 '14 at 18:12
  • Actually I said that because I found this on [PouchDB FAQ](http://pouchdb.com/faq.html#sync_non_couchdb). So, did your backend implement the CouchDB Replication Protocol? – Denis C de Azevedo Nov 02 '14 at 22:08
  • @denisazevedo Sorry you are correct. I got this confused with another library. It looks like it can be achieved with MySQL but it may be a bit of a rigmarole. – Popcorn245 Nov 02 '14 at 22:42
  • @Popcorn245 What library were you thinking of? – Jeremy Apr 08 '15 at 16:02
  • @Jeremy I can't remember what I was using as I abandoned that project shortly after I answered this question. However, I now use FireBase to handle all of my data synchronization needs, it can get a bit costly depending on the size of your application, but the ease of use is worth every penny in my opinion. A free solution is using PouchDB on the front-end and use CouchDB on the backend. – Popcorn245 May 08 '15 at 14:56