-
Notifications
You must be signed in to change notification settings - Fork 24
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
Chainable methods on subscriptions #155
Conversation
This adds a free function called `subscribe` which returns a subscription from a subscribable. It also adds chainable methods via `ChainableSubscription` which makes it possible to call `map`, `filter` and `match` on subscriptions. Finally it deprecates `Subscribable.from` and chaining off of a subscribable.
🦋 Changeset is good to goLatest commit: 784a0bb We got this. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The preview packages of this pull request have been published. @effection/fetchInstall using the following command: $ npm install @effection/fetch@subscription-chainable Or update your package.json file: {
"@effection/fetch": "subscription-chainable"
} @effection/nodeInstall using the following command: $ npm install @effection/node@subscription-chainable Or update your package.json file: {
"@effection/node": "subscription-chainable"
} @effection/subscriptionInstall using the following command: $ npm install @effection/subscription@subscription-chainable Or update your package.json file: {
"@effection/subscription": "subscription-chainable"
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be that the biggest difference here, is whether you're transforming the subscription itself, or the operation that produces the subscription. Are these semi-orthogonal use cases? With the chainable subscription, you need to go through a two step process:
- produce the chainable subscription from the
subscribe
operation. - chain off the chainable subscription:
let subscription: ChainableSubscription<number, void> = yield subscribe(thing);
let first: number = yield subscription.filter(predicate).expect();
vs chaining the operation that produces the subscription in which you:
- create the operation chain.
- produce the subscription yielded by the chain
let first: number = yield Subscribable.from(thing).filter(predicate).expect();
There are a couple tradeoffs for going either way, but from what I can see, there are a couple of advantages to having the operation be transformable rather that the value be transformable. Specifically, if the operation is transformable, then it can be defined outside of any particular effection context. Also, (and this is because of TypeScript's flaws around Generator
typing) the chaining happens all before hand, meaning that you need less annotations to propagate type information across the steps of the chain. In other words, ChainableSubscription<number, void>
which is a keyboard full, is not necessary.
This is all to say that maybe we should have both and not deprecate Subscribable.from()
for the moment? What is the exact use-case enabled by transforming the value, and not the operation that produces the value? Perhaps it would make sense to have them co-exist for awhile and then we can either unify or maintain both based on more data.
Let's keep it around for a while and see how subscriptions pan out.
That makes sense to me. I pushed a commit to undo the deprecation. Let's keep both for a while and see how it pans out. |
This adds a free function called
subscribe
which returns a subscription from a subscribable. It also adds chainable methods viaChainableSubscription
which makes it possible to callmap
,filter
andmatch
on subscriptions.Finally it deprecates
Subscribable.from
and chaining off of a subscribable.Closes #154