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

Subscriptions & resolved #199

Open
samdenty opened this issue Apr 12, 2021 · 0 comments
Open

Subscriptions & resolved #199

samdenty opened this issue Apr 12, 2021 · 0 comments

Comments

@samdenty
Copy link
Owner

samdenty commented Apr 12, 2021

The current API for subscribing to subscriptions is:

resolved(() => {
  return subscription.notification
}, {
  onSubscription(event) {
    switch (event.type) {
      case "complete"
      case "start":
        {
          event.unsubscribe
           break;
        }
      case "data": {
        event.data;
        break;  
      }
     case "with-errors": {
       event.data;
       event.error;
        break;
      }
    }
  }
})

We need some new helper APIs, following the mobx way should be good

resolved and subscriptions

I think the most intuitive way, is that resolved works with subscriptions the same way as queries (so that you can replace stale data in your app with live).

const notification = await resolved(() => {
  return subscription.notification
})

autorun

For listening to a stream of data

const unlisten = autorun(() => {
   // This console logs every time a new notification comes in
   // or when query.something changes in the cache
   console.log(subscription.notification)

   console.log(query.something)
}, (error) => {
  // when an error comes in
  console.log(error)
});

// stops listening for changes
unlisten()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant