bcherny / undux

⚡️ Dead simple state for React. Now with Hooks support.
https://undux.org
MIT License
1.49k stars 31 forks source link

Discussion: Allow effects to return an Observable #89

Closed pvamshi closed 10 months ago

pvamshi commented 4 years ago

Disclaimer: Coming from Angular world 😁!

In libraries like NgRx, NgXs effects we always return an observable. I feel this code snippet

store
  .on('today')
  .pipe(
    debounce(100)
  )
  .subscribe(async date => {
    let users = await api.get({ since: date })
    store.set('users')(users)
  })

can be

store
  .on('today')
  .pipe(
    debounce(100),
    mergeMap( date => {
        return api.get({since: date})
    }),
    map( users => ({users})
  )

I did not put much thought into the syntax. I will try to test this and give you the results. For now, sharing this idea here.