a zip code crypto-currency system good for red ONLY

dom-controller.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "@angular/core", "./platform", "../util/util"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. /**
  13. * Adopted from FastDom
  14. * https://github.com/wilsonpage/fastdom
  15. * MIT License
  16. */
  17. var core_1 = require("@angular/core");
  18. var platform_1 = require("./platform");
  19. var util_1 = require("../util/util");
  20. /**
  21. * @hidden
  22. */
  23. var DomDebouncer = (function () {
  24. function DomDebouncer(dom) {
  25. this.dom = dom;
  26. this.writeTask = null;
  27. this.readTask = null;
  28. }
  29. DomDebouncer.prototype.read = function (fn) {
  30. var _this = this;
  31. if (this.readTask) {
  32. return;
  33. }
  34. return this.readTask = this.dom.read(function (t) {
  35. _this.readTask = null;
  36. fn(t);
  37. });
  38. };
  39. DomDebouncer.prototype.write = function (fn) {
  40. var _this = this;
  41. if (this.writeTask) {
  42. return;
  43. }
  44. return this.writeTask = this.dom.write(function (t) {
  45. _this.writeTask = null;
  46. fn(t);
  47. });
  48. };
  49. DomDebouncer.prototype.cancel = function () {
  50. var writeTask = this.writeTask;
  51. writeTask && this.dom.cancel(writeTask);
  52. var readTask = this.readTask;
  53. readTask && this.dom.cancel(readTask);
  54. this.readTask = this.writeTask = null;
  55. };
  56. return DomDebouncer;
  57. }());
  58. exports.DomDebouncer = DomDebouncer;
  59. /**
  60. * @hidden
  61. */
  62. var DomController = (function () {
  63. function DomController(plt) {
  64. this.plt = plt;
  65. this.r = [];
  66. this.w = [];
  67. }
  68. DomController.prototype.debouncer = function () {
  69. return new DomDebouncer(this);
  70. };
  71. DomController.prototype.read = function (fn, timeout) {
  72. var _this = this;
  73. if (timeout) {
  74. fn.timeoutId = this.plt.timeout(function () {
  75. _this.r.push(fn);
  76. _this._queue();
  77. }, timeout);
  78. }
  79. else {
  80. this.r.push(fn);
  81. this._queue();
  82. }
  83. return fn;
  84. };
  85. DomController.prototype.write = function (fn, timeout) {
  86. var _this = this;
  87. if (timeout) {
  88. fn.timeoutId = this.plt.timeout(function () {
  89. _this.w.push(fn);
  90. _this._queue();
  91. }, timeout);
  92. }
  93. else {
  94. this.w.push(fn);
  95. this._queue();
  96. }
  97. return fn;
  98. };
  99. DomController.prototype.cancel = function (fn) {
  100. if (fn) {
  101. if (fn.timeoutId) {
  102. this.plt.cancelTimeout(fn.timeoutId);
  103. }
  104. util_1.removeArrayItem(this.r, fn) || util_1.removeArrayItem(this.w, fn);
  105. }
  106. };
  107. DomController.prototype._queue = function () {
  108. var self = this;
  109. if (!self.q) {
  110. self.q = true;
  111. self.plt.raf(function rafCallback(timeStamp) {
  112. self._flush(timeStamp);
  113. });
  114. }
  115. };
  116. DomController.prototype._flush = function (timeStamp) {
  117. var err;
  118. try {
  119. dispatch(timeStamp, this.r, this.w);
  120. }
  121. catch (e) {
  122. err = e;
  123. }
  124. this.q = false;
  125. if (this.r.length || this.w.length) {
  126. this._queue();
  127. }
  128. if (err) {
  129. throw err;
  130. }
  131. };
  132. DomController.decorators = [
  133. { type: core_1.Injectable },
  134. ];
  135. /** @nocollapse */
  136. DomController.ctorParameters = function () { return [
  137. { type: platform_1.Platform, },
  138. ]; };
  139. return DomController;
  140. }());
  141. exports.DomController = DomController;
  142. function dispatch(timeStamp, r, w) {
  143. var fn;
  144. // ******** DOM READS ****************
  145. while (fn = r.shift()) {
  146. fn(timeStamp);
  147. }
  148. // ******** DOM WRITES ****************
  149. while (fn = w.shift()) {
  150. fn(timeStamp);
  151. }
  152. }
  153. });
  154. //# sourceMappingURL=dom-controller.js.map