state.js 853 B

1234567891011121314151617181920212223242526272829303132333435
  1. /** @license MIT License (c) copyright 2010-2014 original author or authors */
  2. /** @author Brian Cavalier */
  3. /** @author John Hann */
  4. (function(define) { 'use strict';
  5. define(function() {
  6. return {
  7. pending: toPendingState,
  8. fulfilled: toFulfilledState,
  9. rejected: toRejectedState,
  10. inspect: inspect
  11. };
  12. function toPendingState() {
  13. return { state: 'pending' };
  14. }
  15. function toRejectedState(e) {
  16. return { state: 'rejected', reason: e };
  17. }
  18. function toFulfilledState(x) {
  19. return { state: 'fulfilled', value: x };
  20. }
  21. function inspect(handler) {
  22. var state = handler.state();
  23. return state === 0 ? toPendingState()
  24. : state > 0 ? toFulfilledState(handler.value)
  25. : toRejectedState(handler.value);
  26. }
  27. });
  28. }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));