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

refactor: enhanced thunk registry system #44

Merged
merged 1 commit into from
Jul 30, 2024
Merged

Conversation

neurosnap
Copy link
Owner

The current registry system for thunks works like this:

  • User calls const thunks = createThunks()
  • User creates all thunks const go = thunks.create("go")
  • User registers thunks store.run(thunks.bootup)

However, there's a caveat with this implementation: all thunks must be created before store.run is called. Further, since thunks are created at the module-level, if the module that exports those thunks isn't loaded before thunk.bootup is called then those thunks are silently ignored.

This change will make it so it doesn't matter when a thunk is created, we will "lazy load" it.

We still require store.run(thunks.bootup) to be called -- because we need access to the store and won't have it when creating a thunk.

We are also sending an error whenever a thunk is dispatched without it being registered which should help ensure thunks get properly registered.

We also changed the name of thunks.bootup to thunks.register to make it more clear that this is a registry system.

The current registry system for thunks works like this:

- User calls `const thunks = createThunks()`
- User creates **all** thunks `const go = thunks.create("go")`
- User registers thunks `store.run(thunks.bootup)`

However, there's a caveat with this implementation: all thunks must be
created before `store.run` is called.  Further, since thunks are created
at the module-level, if the module that exports those thunks isn't
loaded before `thunk.bootup` is called then those thunks are silently
ignored.

This change will make it so it doesn't matter when a thunk is created,
we will "lazy load" it.

We still require `store.run(thunks.bootup)` to be called -- because we
need access to the store and won't have it when creating a thunk.

We are also sending an error whenever a thunk is dispatched without it
being registered which should help ensure thunks get properly
registered.

We also changed the name of `thunks.bootup` to `thunks.register` to make
it more clear that this is a registry system.
@neurosnap neurosnap force-pushed the refactor-thunk-registry branch 2 times, most recently from 0086c8e to 3df0306 Compare July 30, 2024 16:28
Copy link
Collaborator

@jbolda jbolda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks lovely to me!

@neurosnap neurosnap merged commit 6ca0a85 into main Jul 30, 2024
8 checks passed
@neurosnap neurosnap deleted the refactor-thunk-registry branch July 30, 2024 19:08
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

Successfully merging this pull request may close these issues.

2 participants