Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

toast-queue.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import _setImmediate from "babel-runtime/core-js/set-immediate";
  2. import _classCallCheck from "babel-runtime/helpers/classCallCheck";
  3. import _createClass from "babel-runtime/helpers/createClass";
  4. /*
  5. Copyright 2013-2015 ASIAL CORPORATION
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. */
  16. var ToastQueue = function () {
  17. function ToastQueue() {
  18. _classCallCheck(this, ToastQueue);
  19. this.queue = [];
  20. }
  21. _createClass(ToastQueue, [{
  22. key: "add",
  23. value: function add(fn, promise) {
  24. var _this = this;
  25. this.queue.push(fn);
  26. if (this.queue.length === 1) {
  27. _setImmediate(this.queue[0]);
  28. }
  29. promise.then(function () {
  30. _this.queue.shift();
  31. if (_this.queue.length > 0) {
  32. setTimeout(_this.queue[0], 1000 / 30); // Apply some visual delay
  33. }
  34. });
  35. }
  36. }]);
  37. return ToastQueue;
  38. }();
  39. export default new ToastQueue();