async mutators
See original GitHub issueIf createMutator
passed the mutate()
method instead of the draft
it could better support async
const { createMutator } = createState({
value: "",
loading: false,
error: null,
});
const updateValue = createMutator(async (mutate, value) => {
mutate(draft => { draft.loading = true; });
try {
await fetch('/api/v1/value', { method: 'POST', ... });
mutate(draft => { draft.value = value; });
} catch (error) {
mutate(draft => { draft.error = error; });
} finally {
mutate(draft => { draft.loading = false; });
}
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Mutators and Orchestrators · GitBook
Orchestrators are the Swiss army knife of Satchel. They may do a variety of things: Perform async operations. Typically the orchestrator will dispatch...
Read more >Request: mutator to remove async/await · Issue #933 - GitHub
In a transition to using async/await from callbacks or Promises, these very important keywords can be lost in merges.
Read more >Adding Mutators - Replicache Docs
Mutators are how you change data in Replicache. Mutators are arbitrary functions that run once on the client immediately (aka “optimistically”), ...
Read more >Writing mutation resolvers | Full-Stack Quickstart
We've written all of the resolvers we need for schema fields that apply to query operations. Now, let's write resolvers for our schema's...
Read more >Message Mutators • NServiceBus • Particular Docs
Message Mutators allow mutation of messages in the pipeline. ... i.e. a pending Task or a CompletedTask , or be marked async ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been looking at ways to write states w/ their mutators in the same module, that might actually be the best way
states/counter.js
components/Counter.js
Do you want to document something like the above pattern?