Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It might be better for fromResource to have dispose function returned from the setup function #309

Open
upsuper opened this issue Sep 23, 2022 · 0 comments

Comments

@upsuper
Copy link
Contributor

upsuper commented Sep 23, 2022

For example, the code in the README would be:

function createObservableUser(dbUserRecord) {
  return fromResource(
    (sink) => {
      // sink the current state
      sink(dbUserRecord.fields)
      // subscribe to the record, invoke the sink callback whenever new data arrives
      const subscription = dbUserRecord.onUpdated(() => {
        sink(dbUserRecord.fields)
      })
      return () => {
        // the user observable is not in use at the moment, unsubscribe (for now)
        dbUserRecord.unsubscribe(subscription)
      }
    },
  )
}

This way we can avoid relying on storing the state outside, making it easier to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant