genkgo / ember-localforage-adapter

Offline usage for Ember Data, based on localstorage adapter, but now uses Mozilla's localforage as data source
Other
133 stars 26 forks source link

Can I observe to IndexDB updates #72

Closed sankar-ganesh closed 7 years ago

sankar-ganesh commented 7 years ago

Is there a way I can observe to IndexDB actions like 'add', 'update', or 'delete'

frederikbosch commented 7 years ago

Nope, why would you want to?

sankar-ganesh commented 7 years ago

To keep multiple tabs that are open to be in sync?

frederikbosch commented 7 years ago

Something like this should work. Requires localForage observerable and a little extension to the default adapter to start observing.

import LFAdapter from 'ember-localforage-adapter/adapters/localforage';

export default LFAdapter.extend({

  startObserveringIndexDb: Ember.on('init', function () {
    var observable = window.localforage.newObservable();
    var subscription = observable.subscribe({
      next: function(args) {
        console.log('I observe everything', args);
      },
      error: function(err) {
        console.log('Found an error!', err);
      },
      complete: function() {
        console.log('Observable destroyed!');
      }
    });
  })

});
sankar-ganesh commented 7 years ago

I couldn't find window.localforage.newObservable

frederikbosch commented 7 years ago

@sankar-ganesh See that link I posted in the previous message. You will need an additional library.

sankar-ganesh commented 7 years ago

As these dependencies are not compatible like an addon ember build doesn't allow me to build it together with the app. By any chance, can i reload the datastore completely to get all of the latest value instead of observing it.

frederikbosch commented 7 years ago

Why not? You can use

app.import('bower_components/x/y.js');

to import external libraries that you installed with bower.

sankar-ganesh commented 7 years ago

BTW, the zen-observer and localforage-observable are not bower components either

frederikbosch commented 7 years ago

Then copy the distributable to your vendor folder.

sankar-ganesh commented 7 years ago

that's right but then it doesn't serve the deployment rules. Instead they have either served the es6 version or the dist folder which can't be used via app.import

frederikbosch commented 7 years ago

Fair enough. Then you should create a PR that adds the feature here. I am prepared to merge it.