ExecutionEnvironment.js.flow 979 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule ExecutionEnvironment
  8. */
  9. 'use strict';
  10. const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
  11. /**
  12. * Simple, lightweight module assisting with the detection and context of
  13. * Worker. Helps avoid circular dependencies and allows code to reason about
  14. * whether or not they are in a Worker, even if they never include the main
  15. * `ReactWorker` dependency.
  16. */
  17. const ExecutionEnvironment = {
  18. canUseDOM: canUseDOM,
  19. canUseWorkers: typeof Worker !== 'undefined',
  20. canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
  21. canUseViewport: canUseDOM && !!window.screen,
  22. isInWorker: !canUseDOM // For now, this is true - might change in the future.
  23. };
  24. module.exports = ExecutionEnvironment;