Skip to content

remove window #121

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

Merged
merged 1 commit into from
Feb 3, 2016
Merged

remove window #121

merged 1 commit into from
Feb 3, 2016

Conversation

ganarajpr
Copy link

Assuming the existence of window means redux-logger cannot be used in universal applications.

This removes the dependency on window being the global variable.

@yocontra
Copy link

yocontra commented Feb 2, 2016

+1

@imevro
Copy link
Collaborator

imevro commented Feb 2, 2016

It breaks default behavior. Pass console to logger option.

@imevro imevro closed this Feb 2, 2016
@ganarajpr
Copy link
Author

I am not sure what default behaviour it breaks. console exists in both browser and nodejs globals. Could you explain ? Using the logger option is not a possibility since this breaks at import - a work around is to do perhaps a conditional import - but that just looks like a mess.

The only thing this removes is an assumption that the global is called window. Could you rationalize why you rejected this PR ?

@yocontra
Copy link

yocontra commented Feb 2, 2016

Uh... what? How does this break any behavior?

@gaearon
Copy link
Contributor

gaearon commented Feb 3, 2016

Unless I'm missing something this should fix Node usage and should not have any effect in the browser. Any downsides?

@gaearon
Copy link
Contributor

gaearon commented Feb 3, 2016

Since we are officially recommending this library on the docs, and people are using Redux on server, we would prefer to see this fixed.

@imevro
Copy link
Collaborator

imevro commented Feb 3, 2016

#12

@esamattis
Copy link
Contributor

It's because the variable is also named console and it shadows the global console object. Rename the console variable or use typeof to check for the window global.

Here's example of what was happening https://jsfiddle.net/Lzmuftt4/

@imevro
Copy link
Collaborator

imevro commented Feb 3, 2016

@epeli no, see screenshot.

@gaearon why does middleware lose console on the third function in carry-functions? On 21 and 23 lines everything ok, but 25 is failed when tried to access global console instead of window.console.
I installed [email protected] with this bug.

frontend 2016-02-03 21-11-12

@imevro imevro reopened this Feb 3, 2016
@esamattis
Copy link
Contributor

I think it's because the var console is being hoisted. The code in the screenshot is same as this:

return function (action) {
  var console; // make the console undefined
  console.log(console);
  var collapsed = options.collapsed;
  var predicate = options.predicate;
  var logger = options.logger;

  console.log(console);
  console = logger || console;
  console.log(console);

..

@imevro
Copy link
Collaborator

imevro commented Feb 3, 2016

@esamattis
Copy link
Contributor

It doesn't need to have. That's the sad magic of var hoisting in Javascript :(

Here's a fiddle demonstrating it https://jsfiddle.net/Lzmuftt4/2/

@imevro
Copy link
Collaborator

imevro commented Feb 3, 2016

@epeli oh wow! But how we can fix it? I don't have an idea.

@esamattis
Copy link
Contributor

Hmm. In the current version there is no more var console. I think you can just merge this PR without any downsides. Or did you see the error with this one too?

imevro pushed a commit that referenced this pull request Feb 3, 2016
@imevro imevro merged commit 4a00216 into LogRocket:master Feb 3, 2016
@imevro
Copy link
Collaborator

imevro commented Feb 3, 2016

@epeli yeah, you are right. Thanks, @ganarajpr @contra @gaearon @epeli!

imevro pushed a commit that referenced this pull request Feb 3, 2016
@imevro
Copy link
Collaborator

imevro commented Feb 3, 2016

Released 2.5.0.

@gaearon
Copy link
Contributor

gaearon commented Feb 3, 2016

Thank you for getting back to this quickly!

@esamattis
Copy link
Contributor

I think here are some old lessons to be learnt again.

I'm gonna enable "no-redeclare": [2, {"builtinGlobals": true}] in my projects...

@hnordt hnordt mentioned this pull request Feb 21, 2016
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

Successfully merging this pull request may close these issues.

5 participants