immediate.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.immediate = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  2. (function (global){
  3. 'use strict';
  4. var Mutation = global.MutationObserver || global.WebKitMutationObserver;
  5. var scheduleDrain;
  6. {
  7. if (Mutation) {
  8. var called = 0;
  9. var observer = new Mutation(nextTick);
  10. var element = global.document.createTextNode('');
  11. observer.observe(element, {
  12. characterData: true
  13. });
  14. scheduleDrain = function () {
  15. element.data = (called = ++called % 2);
  16. };
  17. } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
  18. var channel = new global.MessageChannel();
  19. channel.port1.onmessage = nextTick;
  20. scheduleDrain = function () {
  21. channel.port2.postMessage(0);
  22. };
  23. } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
  24. scheduleDrain = function () {
  25. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  26. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  27. var scriptEl = global.document.createElement('script');
  28. scriptEl.onreadystatechange = function () {
  29. nextTick();
  30. scriptEl.onreadystatechange = null;
  31. scriptEl.parentNode.removeChild(scriptEl);
  32. scriptEl = null;
  33. };
  34. global.document.documentElement.appendChild(scriptEl);
  35. };
  36. } else {
  37. scheduleDrain = function () {
  38. setTimeout(nextTick, 0);
  39. };
  40. }
  41. }
  42. var draining;
  43. var queue = [];
  44. //named nextTick for less confusing stack traces
  45. function nextTick() {
  46. draining = true;
  47. var i, oldQueue;
  48. var len = queue.length;
  49. while (len) {
  50. oldQueue = queue;
  51. queue = [];
  52. i = -1;
  53. while (++i < len) {
  54. oldQueue[i]();
  55. }
  56. len = queue.length;
  57. }
  58. draining = false;
  59. }
  60. module.exports = immediate;
  61. function immediate(task) {
  62. if (queue.push(task) === 1 && !draining) {
  63. scheduleDrain();
  64. }
  65. }
  66. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  67. },{}]},{},[1])(1)
  68. });