Skip to content

Conversation

@jbolda
Copy link
Collaborator

@jbolda jbolda commented Jun 28, 2025

Motivation

By scoping our thunks, we can rely on the context as set specifically in each thunk. With this adjustment, we can allow the user to pass a resource which we attach to a context. They may then use that provide()ed resource in any action which is created under this thunk.

A resource is specifically an effection-type resource. A relevant example would be a WebSocket connection or a worker, both of which are available in effection/x as a package.

Additional Design Notes

This pattern could also possibly be applied to the store. We could have resources at the "store level" which all thunks/apis would be able to use, or you could manage it at a specific thunk/api level.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 28, 2025

More templates

npm i https://pkg.pr.new/neurosnap/starfx@64

commit: b731486

@jbolda
Copy link
Collaborator Author

jbolda commented Jun 28, 2025

Punting on a store .manage() for the moment though, as we really don't have a great place to handle / yield* the resources at the store. It is mostly a builder function which returns a .run to execute Operations in that scope.

I think if we want to enable that, we might have a scope one level above the store. Then the store would "register" in that scope similar to the thunks. This could also be a reasonable extension point where a store has the ability to .manage() or .create() a storage mechanism, ie immerjs resource vs yjs resource, etc. This extension point is in part inspired by this comment.

@jbolda jbolda force-pushed the manage-resource-with-scoped-thunks branch from 087c40c to 1255bf2 Compare July 8, 2025 02:43
@jbolda jbolda marked this pull request as ready for review July 8, 2025 02:56
Copy link
Collaborator

@neurosnap neurosnap left a comment

Choose a reason for hiding this comment

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

nice!

@neurosnap neurosnap merged commit 4c9bc26 into main Aug 2, 2025
6 checks passed
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.

3 participants