Skip to content

Commit

Permalink
refactor(core): use has instead of get to test for existence in ExecE…
Browse files Browse the repository at this point in the history
…nv (#7763)

refactor(core): use has instead of get to test for existence
  • Loading branch information
Josh-Cena authored and slorber committed Jul 14, 2022
1 parent 08f6db8 commit 2729820
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/docusaurus/src/client/exports/ExecutionEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
* LICENSE file in the root directory of this source tree.
*/

const canUseDOM = !!(
const canUseDOM =
typeof window !== 'undefined' &&
window.document &&
window.document.createElement
);
'document' in window &&
'createElement' in window.document;

const ExecutionEnvironment = {
canUseDOM,

// window.attachEvent is IE-specific; it's very likely Docusaurus won't work
// on IE anyway.
canUseEventListeners:
// @ts-expect-error: window.attachEvent is IE specific.
// See https://github.com/Microsoft/TypeScript/issues/3953#issuecomment-123396830
canUseDOM && !!(window.addEventListener || window.attachEvent),
canUseDOM && ('addEventListener' in window || 'attachEvent' in window),

canUseIntersectionObserver: canUseDOM && 'IntersectionObserver' in window,

canUseViewport: canUseDOM && !!window.screen,
canUseViewport: canUseDOM && 'screen' in window,
};

export default ExecutionEnvironment;

0 comments on commit 2729820

Please sign in to comment.