IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

114 Zeilen
3.4KB

  1. const defaultOrderRegistry = {};
  2. /* function notify(orderRegistry) {
  3. if (!('listeners' in orderRegistry))
  4. return;
  5. for (let k in orderRegistry.listeners) {
  6. orderRegistry.listeners[k](orderRegistry);
  7. }
  8. } */
  9. function cursorDecor() {
  10. let d = $('#cursor-decor');
  11. if (d.length === 1)
  12. return $(d[0]);
  13. d = $('<div id="cursor-decor" style="z-index: 10000; position: absolute; left: 10px; top: 10px;"> \
  14. <div class="progress" style="height: 8px;"> \
  15. <div class="progress-bar progress-bar-striped progress-bar-animated" \
  16. role="progressbar" aria-valuenow="100" aria-valuemin="0" \
  17. aria-valuemax="100" style="width: 32px;"></div> \
  18. </div> \
  19. </div>');
  20. $(document.body).append(d);
  21. let pageX = 0, pageY = 0, scrollX = 0, scrollY = 0;
  22. document.addEventListener('mousemove', e => {
  23. pageX = e.pageX;
  24. pageY = e.pageY;
  25. d.css({ left: (e.pageX + 16) + 'px', top: (e.pageY + 16) + 'px' })
  26. scrollX = window.scrollX;
  27. scrollY = window.scrollY;
  28. });
  29. document.addEventListener('scroll', e => {
  30. d.css({ left: (pageX + window.scrollX - scrollX + 16) + 'px',
  31. top: (pageY + window.scrollY - scrollY + 16) + 'px' });
  32. });
  33. return d;
  34. }
  35. function updateCursorDecor(orderRegistry) {
  36. const d = cursorDecor();
  37. if (Object.keys(orderRegistry.pendingCompletion).length === 0)
  38. d.hide();
  39. else
  40. d.show();
  41. }
  42. function wbApplyPromiseOrdering(prom, orderRegistry) {
  43. let orderId;
  44. if (!orderRegistry)
  45. orderRegistry = defaultOrderRegistry;
  46. //if (Object.keys(orderRegistry).length === 0) {
  47. if (!('started' in orderRegistry)) {
  48. orderRegistry.started = 0;
  49. orderRegistry.pendingCompletion = {};
  50. orderRegistry.completed = { 0: true };
  51. }
  52. orderRegistry.started += 1;
  53. orderId = orderRegistry.started;
  54. // console.log('New orderId: ' + orderId);
  55. // notify(orderRegistry);
  56. cursorDecor().show();
  57. const orderCallback = ((isCatch, payload) => {
  58. // console.log('orderId: ' + orderId +
  59. // ', pendingCompletion: ' + Object.keys(orderRegistry.pendingCompletion) +
  60. // ', completed: ' + Object.keys(orderRegistry.completed));
  61. if ((orderId - 1) in orderRegistry.completed) {
  62. // console.log('Running: ' + orderId);
  63. orderRegistry.completed[orderId] = true;
  64. delete orderRegistry.pendingCompletion[orderId];
  65. const keys = Object.keys(orderRegistry.pendingCompletion);
  66. keys.sort((a, b) => (a - b));
  67. keys.map(k => {
  68. if ((k - 1) in orderRegistry.completed) {
  69. // console.log('Running: ' + k);
  70. orderRegistry.pendingCompletion[k]();
  71. orderRegistry.completed[k] = true;
  72. delete orderRegistry.pendingCompletion[k];
  73. }
  74. });
  75. if (orderRegistry.started in orderRegistry.completed) {
  76. // console.log('Garbage collect');
  77. orderRegistry.started = 0;
  78. orderRegistry.completed = { 0: true };
  79. cursorDecor().hide();
  80. }
  81. if (isCatch)
  82. throw payload;
  83. else
  84. return payload;
  85. }
  86. const prom_1 = new Promise((accept, reject) => {
  87. orderRegistry.pendingCompletion[orderId] = (() =>
  88. (isCatch ? reject(payload) : accept(payload)));
  89. });
  90. return prom_1;
  91. });
  92. prom = prom.then(xhr => orderCallback(false, xhr));
  93. prom = prom.catch(e => orderCallback(true, e));
  94. return prom;
  95. }
  96. export default wbApplyPromiseOrdering;