rsvp.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import Promise from './rsvp/promise';
  2. import EventTarget from './rsvp/events';
  3. import denodeify from './rsvp/node';
  4. import all from './rsvp/all';
  5. import allSettled from './rsvp/all-settled';
  6. import race from './rsvp/race';
  7. import hash from './rsvp/hash';
  8. import hashSettled from './rsvp/hash-settled';
  9. import rethrow from './rsvp/rethrow';
  10. import defer from './rsvp/defer';
  11. import {
  12. config,
  13. configure
  14. } from './rsvp/config';
  15. import map from './rsvp/map';
  16. import resolve from './rsvp/resolve';
  17. import reject from './rsvp/reject';
  18. import filter from './rsvp/filter';
  19. import asap from './rsvp/asap';
  20. // defaults
  21. config.async = asap;
  22. config.after = cb => setTimeout(cb, 0);
  23. const cast = resolve;
  24. const async = (callback, arg) => config.async(callback, arg);
  25. function on() {
  26. config['on'].apply(config, arguments);
  27. }
  28. function off() {
  29. config['off'].apply(config, arguments);
  30. }
  31. // Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`
  32. if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') {
  33. let callbacks = window['__PROMISE_INSTRUMENTATION__'];
  34. configure('instrument', true);
  35. for (let eventName in callbacks) {
  36. if (callbacks.hasOwnProperty(eventName)) {
  37. on(eventName, callbacks[eventName]);
  38. }
  39. }
  40. }
  41. import platform from './rsvp/platform';
  42. // the default export here is for backwards compat:
  43. // https://github.com/tildeio/rsvp.js/issues/434
  44. export default {
  45. asap,
  46. cast,
  47. Promise,
  48. EventTarget,
  49. all,
  50. allSettled,
  51. race,
  52. hash,
  53. hashSettled,
  54. rethrow,
  55. defer,
  56. denodeify,
  57. configure,
  58. on,
  59. off,
  60. resolve,
  61. reject,
  62. map,
  63. ['async']: async, // babel seems to error if async isn't a computed prop here...
  64. filter
  65. };
  66. export {
  67. asap,
  68. cast,
  69. Promise,
  70. EventTarget,
  71. all,
  72. allSettled,
  73. race,
  74. hash,
  75. hashSettled,
  76. rethrow,
  77. defer,
  78. denodeify,
  79. configure,
  80. on,
  81. off,
  82. resolve,
  83. reject,
  84. map,
  85. async,
  86. filter
  87. };