simpla icon indicating copy to clipboard operation
simpla copied to clipboard

Move from Promises to Observables

Open madeleineostoja opened this issue 8 years ago • 0 comments

Simpla currently uses promises and observer methods to react to data, eg:

Simpla.get('/foo').then(...);
Simpla.observe('/foo', () => { ... });

This has a few problems:

  • Duped logic between a one-time reaction (promise) and continued reactions (observer), when really these are the same thing

  • Handshake issues when both getting and observing a path while it's in transit and filling the buffer

  • Growing number of observer methods that all do the same thing to different pieces of data (observe, observeState, observeQuery once we reimplement indexes)

Instead, Simpla should return ES6 observables, using a library like RxJS or zen-observable.

The new API would look something like this

// Get data
Simpla.get('/foo')
  .subscribe(..., { once: true });

// Observe data changes
let foo = Simpla.get('/foo')
  .subscribe(...);

// Stop an observer
foo.unsubscribe();

madeleineostoja avatar Oct 18 '17 22:10 madeleineostoja