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

Debug flag for the dispatcher #27

Open
ferrannp opened this issue Jan 13, 2015 · 7 comments
Open

Debug flag for the dispatcher #27

ferrannp opened this issue Jan 13, 2015 · 7 comments

Comments

@ferrannp
Copy link

As it is written here:

http://www.code-experience.com/async-requests-with-react-js-and-flux-revisited/
There should be only one channel for all state changes: The Dispatcher. This makes debugging easy because it just requires a single console.log in the dispatcher to observe every single state change trigger.

I am missing this "console.log" when the Dispatcher is using "dispatch" so it's very easy and fast to see every time that some action has been dispatched (and I don't need console.log in all the Stores).

Will you be able to add some debug flag to set this console.log on or off? Something like:

Dispatcher.dispatch(payload)
if(DEBUG){
  console.log(payload)
}

Or maybe like React does:

if ("production" !== process.env.NODE_ENV){
  console.log(payload)
}

Thanks in advance!

@balanceiskey
Copy link
Contributor

An alternate you might consider trying that we've had success with is simply creating a DebugStore whose only responsibility is to log payloads.

@ferrannp
Copy link
Author

@balanceiskey indeed, that could be a good approach... However, I think adding the second suggested piece of code would be better.

@buberdds
Copy link

@ferrannp Yeah, this piece of code won't hurt anyone and is quite useful +1

@kenwheeler
Copy link
Owner

@balanceiskey @ferrannp I'll be reviewing this this weekend.

@kenwheeler
Copy link
Owner

I'm not sure if implicitly including a debug mode, like example 2 is really desired as a core feature. That said, does anyone have any ideas around passing a debug flag? I'm having difficulty creating a global debug flag with browserify.

@tomatau
Copy link
Contributor

tomatau commented Jan 31, 2015

Perhaps attach a debug flag to the McFly instance?

Webpack has good functionality for global flags but a modular framework should definitely not assume a build process, also, it's nice to support people who like to add their scripts individually to an html file! (without globals)

I find the debug logging store to be the most flexible solution here!

@kraf
Copy link

kraf commented Feb 5, 2015

I've been just dropping this snippet in my main entry points:

var Flux = require('wherever-you-build-flux');
Flux.dispatcher.register(function debugOutput(payload) {
    if(localStorage.debugDispatch === "true") {
        console.log(Date(), payload.actionType, payload);
    }
});

I like being able to enable/disable this in the console while the application is running.

@kenwheeler: Browserify gives you access to process.env. I'm pretty sure you can read anything from the environment, not just NODE_ENV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants