Skip to content

How would I use this with socket.io? #4

@justinireland

Description

@justinireland

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.

const reducer = asyncInitialState.outerReducer(combineReducers({
    ...rootReducer,
    asyncInitialState: asyncInitialState.innerReducer,
}))

socket.emit('getInitialState')

const loadStore = () => {
    return new Promise(resolve => {
        socket.on('getInitialState', (initialState) => resolve(initialState))
    })
}

const storeCreator = applyMiddleware(
    asyncInitialState.middleware(loadStore),
    socketIoMiddleware(socket)
)
const store = storeCreator(reducer)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions