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
I want to get the current action from store. #1243
Comments
Please see #1057, this is the same request. |
I found an exact solution to this issue. So I leave the link below. Sending Actions To The Server Using Redux Middleware[ http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html#sending-actions-to-the-server-using-redux-middleware ] src/components/index.jsx import {createStore, applyMiddleware} from 'redux';
import io from 'socket.io-client';
import remoteActionMiddleware from './remote_action_middleware';
const socket = io(`${location.protocol}//${location.hostname}:8090`);
socket.on('state', state =>
store.dispatch(setState(state))
);
const createStoreWithMiddleware = applyMiddleware(
remoteActionMiddleware(socket)
)(createStore);
const store = createStoreWithMiddleware(reducer); src/remote_action_middleware.js export default socket => store => next => action => {
if (action.meta && action.meta.remote) {
socket.emit('action', action);
}
return next(action);
} src/action_creators.js export function vote(entry) {
return {
meta: {remote: true},
type: 'VOTE',
entry
};
} |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
store has "subscribe" method to notify "the change of state" to all the subscribing clients.
It will be convenient if the current action is able to be sent to the clients in 'subscribe' method.
Current state can be obtained from store.getState().
But there is no such method to get the current action from store
( for example, store.getAction() which will return the current action dispatched to the store )
Any idea is appreciated.
The text was updated successfully, but these errors were encountered: