Skip to content

Commit

Permalink
fix(browser): remove global.window for node.js (#233)
Browse files Browse the repository at this point in the history
fix(browser): remove global.window for node.js
Close #232
  • Loading branch information
daybrush authored Oct 15, 2018
1 parent f75590d commit b9ae32a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/react-infinitegrid/src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export const CHECK_ONLY_ERROR = 2;
export const CONTAINER_CLASSNAME = "_eg-infinitegrid-container_";
export const LAYOUT_ID = "__REACT_LAYOUT_DATA_ID__";
export const DUMMY_POSITION = -999999;
export const SUPPORT_COMPUTEDSTYLE = !!("getComputedStyle" in window);
export const SUPPORT_COMPUTEDSTYLE = typeof window === "undefined" ? false : !!("getComputedStyle" in window);
3 changes: 3 additions & 0 deletions src/Watcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
IS_IOS,
} from "./consts";
import {
window,
} from "./browser";
import {
addEvent,
removeEvent,
Expand Down
8 changes: 6 additions & 2 deletions src/browser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* eslint-disable no-new-func, no-nested-ternary */

let win;

if (typeof window === "undefined") {
global.window = {
// window is undefined in node.js
win = {
document: {},
navigator: {
userAgent: "",
},
};
} else {
win = window;
}
const win = window;
/* eslint-enable no-new-func, no-nested-ternary */

export {win as window};
Expand Down

0 comments on commit b9ae32a

Please sign in to comment.