simplajs / simpla

Open, modular, and serverless content management for a modern web
https://www.simplajs.org
MIT License
527 stars 36 forks source link

Move from Promises to Observables #76

Open madeleineostoja opened 7 years ago

madeleineostoja commented 7 years ago

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

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

This has a few problems:

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();