bcherny / undux

โšก๏ธ Dead simple state for React. Now with Hooks support.

Home Page:https://undux.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discussion: Allow effects to return an Observable

pvamshi opened this issue ยท comments

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.