@bbn/bbn 1.0.424 → 1.0.426

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,7 @@
1
- export default function executeSlowly(arr: any[], fn: Function): Promise<void>;
1
+ /**
2
+ * Executes a function on each element of an array slowly, yielding to the browser in between.
3
+ * @param arr The array to iterate over.
4
+ * @param fn The function to execute on each element. If the function returns false, the iteration stops.
5
+ * @returns A promise that resolves to true if the iteration completed, or false if it was stopped early.
6
+ */
7
+ export default function executeSlowly(arr: any[], fn: Function): Promise<boolean>;
@@ -35,6 +35,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import yieldToBrowser from './yieldToBrowser.js';
38
+ /**
39
+ * Executes a function on each element of an array slowly, yielding to the browser in between.
40
+ * @param arr The array to iterate over.
41
+ * @param fn The function to execute on each element. If the function returns false, the iteration stops.
42
+ * @returns A promise that resolves to true if the iteration completed, or false if it was stopped early.
43
+ */
38
44
  export default function executeSlowly(arr, fn) {
39
45
  return __awaiter(this, void 0, void 0, function () {
40
46
  var i, res;
@@ -53,7 +59,7 @@ export default function executeSlowly(arr, fn) {
53
59
  _a.label = 3;
54
60
  case 3:
55
61
  if (res === false) {
56
- return [3 /*break*/, 6];
62
+ return [2 /*return*/, false];
57
63
  }
58
64
  return [4 /*yield*/, yieldToBrowser()];
59
65
  case 4:
@@ -62,7 +68,7 @@ export default function executeSlowly(arr, fn) {
62
68
  case 5:
63
69
  i++;
64
70
  return [3 /*break*/, 1];
65
- case 6: return [2 /*return*/];
71
+ case 6: return [2 /*return*/, true];
66
72
  }
67
73
  });
68
74
  });
@@ -1 +1,13 @@
1
+ /**
2
+ * Yields execution to the browser to allow it to process pending UI updates.
3
+ * Uses `window.scheduler.yield()` if available, otherwise falls back to `requestAnimationFrame`.
4
+ * @method yieldToBrowser
5
+ * @global
6
+ * @example
7
+ * ``` javascript
8
+ * await bbn.fn.yieldToBrowser();
9
+ * ```
10
+ * @memberof bbn.fn
11
+ * @returns {Promise}
12
+ */
1
13
  export default function yieldToBrowser(): Promise<void>;
@@ -34,20 +34,33 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ /**
38
+ * Yields execution to the browser to allow it to process pending UI updates.
39
+ * Uses `window.scheduler.yield()` if available, otherwise falls back to `requestAnimationFrame`.
40
+ * @method yieldToBrowser
41
+ * @global
42
+ * @example
43
+ * ``` javascript
44
+ * await bbn.fn.yieldToBrowser();
45
+ * ```
46
+ * @memberof bbn.fn
47
+ * @returns {Promise}
48
+ */
37
49
  export default function yieldToBrowser() {
38
50
  return __awaiter(this, void 0, void 0, function () {
39
- return __generator(this, function (_a) {
40
- switch (_a.label) {
51
+ var _a;
52
+ return __generator(this, function (_b) {
53
+ switch (_b.label) {
41
54
  case 0:
42
- if (!('scheduler' in window)) return [3 /*break*/, 2];
55
+ if (!((_a = window.scheduler) === null || _a === void 0 ? void 0 : _a.yield)) return [3 /*break*/, 2];
43
56
  return [4 /*yield*/, window.scheduler.yield()];
44
57
  case 1:
45
- _a.sent(); // cooperative yield
58
+ _b.sent(); // cooperative yield
46
59
  return [3 /*break*/, 4];
47
60
  case 2: return [4 /*yield*/, new Promise(requestAnimationFrame)];
48
61
  case 3:
49
- _a.sent();
50
- _a.label = 4;
62
+ _b.sent();
63
+ _b.label = 4;
51
64
  case 4: return [2 /*return*/];
52
65
  }
53
66
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.424",
3
+ "version": "1.0.426",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",