ExecutionEnvironment.js 935 B

123456789101112131415161718192021222324252627282930313233
  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. */
  8. 'use strict';
  9. var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
  10. /**
  11. * Simple, lightweight module assisting with the detection and context of
  12. * Worker. Helps avoid circular dependencies and allows code to reason about
  13. * whether or not they are in a Worker, even if they never include the main
  14. * `ReactWorker` dependency.
  15. */
  16. var ExecutionEnvironment = {
  17. canUseDOM: canUseDOM,
  18. canUseWorkers: typeof Worker !== 'undefined',
  19. canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
  20. canUseViewport: canUseDOM && !!window.screen,
  21. isInWorker: !canUseDOM // For now, this is true - might change in the future.
  22. };
  23. module.exports = ExecutionEnvironment;