simpla
simpla copied to clipboard
Move from Promises to Observables
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,observeQueryonce 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();