Skip to content

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

@upsuper

Description

@upsuper

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions