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

Fix to devtools-plugin to support Actions without a "callback" param #460

Merged
merged 1 commit into from
Jul 19, 2016
Merged
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
6 changes: 5 additions & 1 deletion packages/fluxible-plugin-devtools/src/lib/devtools-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export default function devToolsPlugin() {
return action(ctx, payload, cb);
}

function timedActionNoCallback(ctx, payload) {
return timedAction(ctx, payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to call these two lines before returning timedAction

actionReference.startTime = Date.now();
actionReference.payload = JSON.stringify(payload);

Without a start time these actions might not end up in the correct place in the timeline. The payload will also be useful for debugging actions called w/o a callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call to "timedAction" sets those values already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed to show up in the correct place in the timeline for me

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, you're right, I thought you were directly calling the action just w/o a callback.

}

function timedCallback(err, data) {
const endTime = Date.now();
const dur = endTime - actionReference.startTime;
Expand All @@ -155,7 +159,7 @@ export default function devToolsPlugin() {

return {
actionContext: actionContext,
action: timedAction,
action: (action.length < 3) ? timedActionNoCallback : timedAction,
Copy link
Contributor

Choose a reason for hiding this comment

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

Actions can also return promises so this might effect those too.

Copy link
Contributor Author

@carystanley carystanley Jul 18, 2016

Choose a reason for hiding this comment

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

timedAction does a return on the wrapped action, and timedActionNoCallback returns the return value of timedAction, so if a promise is returned it would be returned

payload: options.payload,
done: timedCallback
};
Expand Down