-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How would I use this with socket.io? #4
Comments
@justinireland Hello! For me your code looks good. I have few questions:
|
const loadStore = () => {
socket.emit('getInitialState')
return new Promise(resolve => {
socket.on('getInitialState', (initialState) => {
console.log(initialState)
return (initialState)
})
.then(resolve)
})
} the emit event never even fires. I suspect the problem is mostly related in how I am trying to emit and subscribe to the channel. I'm not very familiar with promises so I may be doing something obviously wrong. |
@justinireland so, as I said probably you are subscribing to this event after it is fired. I'd try to do something like this: const initialStatePromise = new Promise(resolve => {
socket.on('getInitialState', resolve);
});
const loadStore = () => {
socket.emit('getInitialState');
return initialStatePromise;
}; |
I'm a little confused by the documentation how I would go about using this for a socket event instead of a fetch request.
For example, I am using socket.io and have setup a special channel called 'getInitialState' to hydrate the initialState from the server. I'm also using socketIoMiddleware for dispatching actions to the server.
The following code doesnt seem to ever resolve even though I have verified the server is emitting the initialState object.
The text was updated successfully, but these errors were encountered: