Skip to content
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

[Fixed #750] Flow actions mutations not syncing to Redux DevTools. #1032

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/mst-middlewares/src/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ export function connectReduxDevtools(remoteDevDep: any, model: any) {
true
)

// Fix for issue #750
//
// By only hooking into the 'onAction' notification, the Redux middleware
// was handling flow (async) actions at their beginning, where the state
// has not changed yet. So we define another middleware to intercept
// "flow_return" action types, which is when the async action is done and
// the new state is available. Ideally, we would exclude the regular "action"
// type for these, but at the time the middleware is invoked with
// `call.type = "action"` there is no way to determine if this is in fact
// an async action.
mst.addMiddleware(model, actionMiddleware)
function actionMiddleware(call: mst.IMiddlewareEvent, next: any) {
if (!applyingSnapshot && call.type === "flow_return") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably remove && call.type === "flow_return" and the onAction code

const copy: any = {}
copy.type = `${call.name} [${call.type}]`
if (call.args) call.args.forEach((value, index) => (copy[index] = value))
remotedev.send(copy, mst.getSnapshot(model))
}

next(call)
}

function handleMonitorActions(remotedev2: any, model2: any, message: any) {
switch (message.payload.type) {
case "RESET":
Expand Down