@init and async function
See original GitHub issueLook like if pass the async function to @init
then storage doesn’t update. I have written small test for this:
it('update state with async @init', () => {
function init (store) {
store.on('@init', async () => ({ a: 1, c: 2 }))
}
let store = createStore([init])
expect(store.get()).toEqual({ a: 1, c: 2 }) // here will be empty object
})
How I can handle it?
I need it in https://github.com/storeon/localstorage because some storage should be fired with await in @init
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to set class attribute with await in __init__ - Stack Overflow
class aobject(object): """Inheriting this class allows you to define an async __init__. So you can create objects by doing something like `await ......
Read more >async function expression - JavaScript - MDN Web Docs
An async function expression can be used as an IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined. See...
Read more >Initialize app with an Async function | SwiftUI - Apple Developer
I need my app to configure the backend at start, here's the function to do so: // Initializes Amplify final func configureAmplify() async...
Read more >The Proper Way to Write Async Constructors in JavaScript
The static async factory function pattern allows us to emulate asynchronous constructors in JavaScript. At the core of this pattern is the ...
Read more >How to do asynchronous operation in object constructor
Approach 2 - Use async initializer() method ... Another approach is to dedicate the constructor for initializing variables and have a separate asynchronous...
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 Free
Top 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
You need to wait that 500 ms before calling
expect()
. Try:You need to dispatch another event and change data there:
We added this limit for a purpose to always have an event in history on any state changes.