-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add a "jobs" system to the listener middleware #1792
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
Conversation
/cc @FaberVitale fyi if you're interested |
✔️ Deploy Preview for redux-starter-kit-docs ready! 🔨 Explore the source changes: c4e1848 🔍 Inspect the deploy log: https://app.netlify.com/sites/redux-starter-kit-docs/deploys/61aae2c8a7d4b80007c231cc 😎 Browse the preview: https://deploy-preview-1792--redux-starter-kit-docs.netlify.app |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c4e1848:
|
size-limit report 📦
|
Update: As of merging #1799 , we now have It's late and I want to do some more polishing before I publish a 0.4.0 (including updating the README), but this is looking very encouraging so far. |
d267ac1
to
01e2464
Compare
01e2464
to
c4e1848
Compare
Just added a test file demonstrating equivalence with multiple Redux-Saga operators:
I think that's sufficient evidence that this branch is worth merging and releasing. |
This is very experimental stuff atm - I'm just pushing so the code is visible and I get some CI runs.
The idea here is to give the listener middleware additional capabilities that better match the feature set of sagas: cancelation of previous tasks for a a given listener, and the ability to launch child tasks. This would enable a large variety of use cases, like implementing the equivalent of
takeLatest()
,fork()
, etc.For reference, I asked about how people use those APIs here: https://twitter.com/acemarke/status/1465017211265994757
I've copied in the source code from https://github.com/ethossoftworks/job-ts , which is a very neat little lib that has a
Job
class that already implements parent/child hierarchical tasking and cancelation.The first step was wrapping the call to the listener function in a new
Job
instance. This gives us aJobHandle
that we can pass in as part of thelistenerApi
. Additionally, theJob
library uses https://github.com/ethossoftworks/outcome-ts as a functional-Option
-style handler for success/error results. I used that to consolidate the error handling for listeners, although I did drop the "sync/async" aspect to the error reporting.Conceptually, I then want the
condition/take
functions to throwJobCancelationError
s if the current listener is canceled, and that's where my brain halted for the night. I was starting to try to restructurecreateTakePattern
, but am realizing that A) the parent job doesn't give me a notice when it's canceled, and B) the call toaddListener()
wouldn't ever give me access to the nestedlistenerApi.job
because the point is that cancelation happens before its listener ever runs.So, a couple thoughts:
AbortController
to theJob
class so that you could listen for thattake/condition
to be based around theJob.pause()
function insteadThe latter approach is appealing, because there's already a
Job.delay()
function that has a timeout, it just doesn't return anything. It would be trivial to do the same thing but with a return value.I really feel like I'm onto something here, but it's late and the pieces just aren't quite coming together in my head.