mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 04:07:32 +02:00
refactor(core): use has instead of get to test for existence in ExecEnv (#7763)
refactor(core): use has instead of get to test for existence
This commit is contained in:
parent
f21dadf621
commit
636d47060e
1 changed files with 7 additions and 8 deletions
|
@ -5,23 +5,22 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const canUseDOM = !!(
|
const canUseDOM =
|
||||||
typeof window !== 'undefined' &&
|
typeof window !== 'undefined' &&
|
||||||
window.document &&
|
'document' in window &&
|
||||||
window.document.createElement
|
'createElement' in window.document;
|
||||||
);
|
|
||||||
|
|
||||||
const ExecutionEnvironment = {
|
const ExecutionEnvironment = {
|
||||||
canUseDOM,
|
canUseDOM,
|
||||||
|
|
||||||
|
// window.attachEvent is IE-specific; it's very likely Docusaurus won't work
|
||||||
|
// on IE anyway.
|
||||||
canUseEventListeners:
|
canUseEventListeners:
|
||||||
// @ts-expect-error: window.attachEvent is IE specific.
|
canUseDOM && ('addEventListener' in window || 'attachEvent' in window),
|
||||||
// See https://github.com/Microsoft/TypeScript/issues/3953#issuecomment-123396830
|
|
||||||
canUseDOM && !!(window.addEventListener || window.attachEvent),
|
|
||||||
|
|
||||||
canUseIntersectionObserver: canUseDOM && 'IntersectionObserver' in window,
|
canUseIntersectionObserver: canUseDOM && 'IntersectionObserver' in window,
|
||||||
|
|
||||||
canUseViewport: canUseDOM && !!window.screen,
|
canUseViewport: canUseDOM && 'screen' in window,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ExecutionEnvironment;
|
export default ExecutionEnvironment;
|
||||||
|
|
Loading…
Add table
Reference in a new issue