itaylor / redux-socket.io

An opinionated connector between socket.io and redux
410 stars 53 forks source link

bindActionCreators and socket.on('action', ...) #7

Closed walkerrandolphsmith closed 8 years ago

walkerrandolphsmith commented 8 years ago

When the following is run on the client

store.dispatch({type:'server/hello', data:'Hello!'});

The server successfully receives the message.

socket.on('action', action => {
    console.log('Got hello data!', action.data);
});

All action creators bound to my component using redux's bindActionCreators are dispatched on the client, but not received by the server. Am I missing something?

itaylor commented 8 years ago

Hmm... Hard to say what could be going wrong there. bindActionCreators doesn't do very much, and it should be calling dispatch in the same way as just calling store.dispatch. Are you sure that the events that your action creators return have type properties that will be matched by your configuration passed to createSocketIoMiddleware?

walkerrandolphsmith commented 8 years ago

I didn't make the connection that createSocketIoMiddleware configured the prefix to the action type. This solved my problem. This can be closed.

Thanks!