Closed hhff closed 7 years ago
It should work (and works on my machine), as even though store
is being declared afterwards, whats being passed in to electronEnhancer
is a callback, so the store.dispatch
line doesn't actually get ran until dispatchProxy
gets called, which happens once the store exists.
Its unfortunate that it has to be this way, but I'm not sure if there's a nicer way to do this using store enhancers. I essentially need the dispatch
function of the final store, but the electronEnhancer
is used while creating the store 😞
Does it not work for you when you run it? A similar setup without having this usage before definition would be
let storeDispatch;
let enhancer = compose(
...
electronEnhancer({ dispatchProxy: a => storeDispatch(a) });
});
let store = createStore(reducer, initialState, enhancer);
storeDispatch = store.dispatch;
Maybe that would work instead?
@hhff are you transpiling your code at all? if so, which transpiler & version? (might be good to paste your code here too) The electronEnhancer
function (from what I can tell) does not call dispatchProxy
immediately.
I don't see anything wrong with the README example, so this is a pretty interesting issue!
Hi @adamdicarlo I switched to a different electron redux lib (https://github.com/hardchor/electron-redux) because I couldn't get this up and running. It works great!
The example in the README could not possibly work in any dialect of JS - at the time the enhancer is declared, store is not defined.
@samiskin's example above should work, as the variable is allocated for the call before the declaration. I was messing around with a few different options, and couldn't get this working immediately due to that issue, so I switched before I arrived at Sam's solution. Thought I should flag it here.
Hi @samiskin !
Question about the docs:
When explaining how to use the electron enhancer:
The
store.dispatch(a)
call is defined before the store has been instantiated, and thus you getstore is undefined
when the app boots.Not sure how I'm supposed to declare the dispatch call without the store instantiated earlier in the file?
TY for all your hard work!