isPending(fn) is useful for checking whether a specific reactive read depends on pending async work, but it cannot currently distinguish or anticipate sources that an action is expected to update.
For example:
const user = createProjection(() => getUser(), {} as User)
const updateUser = action(function* (name: string) {
yield updateUserServer(name)
refresh(user)
})
In this case:
isPending(() => user.name)
only becomes true once refresh(user) starts. There is no way for the action to say "this source is affected by this mutation" earlier.
Proposed API
const updateUser = action(function* (name: string) {
affects(user)
yield updateUserServer(name)
})
Expected Behavior
affects(user) marks user as pending for isPending() while the action is running.
- It does not mutate or refresh the source.
- It clears when the action settles.
- It should throw in dev mode if called outside an
action.
- It should accept the same refreshable targets as
refresh().
Example Usage
const pending = createMemo(() =>
isPending(() => user.name)
)
const updateUser = action(function* (name: string) {
affects(user)
yield updateUserServer(name)
refresh(user)
})
This lets UI show "saving/updating" state immediately for the affected source, instead of waiting for the later refresh.
isPending(fn)is useful for checking whether a specific reactive read depends on pending async work, but it cannot currently distinguish or anticipate sources that anactionis expected to update.For example:
In this case:
only becomes
trueoncerefresh(user)starts. There is no way for the action to say "this source is affected by this mutation" earlier.Proposed API
Expected Behavior
affects(user)marksuseras pending forisPending()while the action is running.action.refresh().Example Usage
This lets UI show "saving/updating" state immediately for the affected source, instead of waiting for the later refresh.