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

feat!: improve injectPromise - add dataSignal, initialData, ZeduxPromise #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bowheart
Copy link
Collaborator

@affects atoms, react, stores

Description

Implement all injectPromise improvements discussed in #220 for Zedux v2:

  • Rename initialState to initialData
  • Replace the dataOnly with a new dataSignal that's both returned from injectPromise and passed to the promise factory callback function.
  • Rework the promise factory's arguments. Instead of receiving a single AbortController, it now receives an object with { controller, dataSignal } properties.
  • Create a new ZeduxPromise type that is a drop-in replacement for any atom's Promise generic and holds the type of injectPromise's resolved data value.
    • Improve overloads of useAtomState and useAtomValue to know that the value is resolved when using suspense. Use the new ZeduxPromise type to infer that value.
    • Create a new ResolvedStateOf type helper

Also improve injectStorePromise:

  • Rename initialState to initialData
  • Add ZeduxPromise types for better hook suspense inference.

I didn't update injectStorePromise to pass the store as an argument to the promise factory. I figure that's an advanced usage and if people want it, we can just say they need to use the signals-based injectPromise instead.

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.

1 participant