a zip code crypto-currency system good for red ONLY

dom-controller.js 3.6KB

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