ExecutionEnvironment.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright (c) 2015, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. * @providesModule ExecutionEnvironment
  10. */
  11. /*jslint evil: true */
  12. 'use strict';
  13. var canUseDOM = !!(
  14. typeof window !== 'undefined' &&
  15. window.document &&
  16. window.document.createElement
  17. );
  18. /**
  19. * Simple, lightweight module assisting with the detection and context of
  20. * Worker. Helps avoid circular dependencies and allows code to reason about
  21. * whether or not they are in a Worker, even if they never include the main
  22. * `ReactWorker` dependency.
  23. */
  24. var ExecutionEnvironment = {
  25. canUseDOM: canUseDOM,
  26. canUseWorkers: typeof Worker !== 'undefined',
  27. canUseEventListeners:
  28. canUseDOM && !!(window.addEventListener || window.attachEvent),
  29. canUseViewport: canUseDOM && !!window.screen,
  30. isInWorker: !canUseDOM // For now, this is true - might change in the future.
  31. };
  32. module.exports = ExecutionEnvironment;