feat!: improve injectPromise
- add dataSignal
, initialData
, ZeduxPromise
#222
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@affects atoms, react, stores
Description
Implement all
injectPromise
improvements discussed in #220 for Zedux v2, with one change: Instead of passing the fulldataSignal
to the callback function, pass the dataSignal's current value asprevData
.After digging in, I saw this change was necessary for two reasons:
unknown
, even when usingNoInfer
on the dataSignal's type. WithprevData
andNoInfer
, TS also infersunknown
, but it's much easier to manually typeprevData
thandataSignal
to fix it. If you don't actually useprevData
, inference works as normal. Since it should be rare that you needprevData
, I'm fine requiring manual typing when you do.dataSignal
's value, even if you set it manually right before the promise factory returned.Full change list:
initialState
toinitialData
dataOnly
with a newdataSignal
that's returned frominjectPromise
. This signal's value is also passed to theinjectPromise
promise factory:{ controller, prevData }
properties.ZeduxPromise
type that is a drop-in replacement for any atom'sPromise
generic and holds the type ofinjectPromise
's resolveddata
value.useAtomState
anduseAtomValue
to know that the value is resolved when using suspense. Use the newZeduxPromise
type to infer that value.ResolvedStateOf
type helperAlso improve
injectStorePromise
:initialState
toinitialData
ZeduxPromise
types for better hook suspense inference.I didn't update
injectStorePromise
to passprevData
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-basedinjectPromise
instead.