lib0 0.2.101 → 0.2.103

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.
Files changed (77) hide show
  1. package/array.d.ts +1 -0
  2. package/array.d.ts.map +1 -1
  3. package/array.js +36 -0
  4. package/array.test.d.ts +2 -0
  5. package/array.test.d.ts.map +1 -1
  6. package/coverage/tmp/coverage-131665-1744412653331-0.json +1 -0
  7. package/dist/aes-gcm.cjs +4 -4
  8. package/dist/{array-8d6422a6.cjs → array-df2f5859.cjs} +40 -2
  9. package/dist/array-df2f5859.cjs.map +1 -0
  10. package/dist/array.cjs +2 -1
  11. package/dist/array.cjs.map +1 -1
  12. package/dist/array.d.ts +1 -0
  13. package/dist/array.d.ts.map +1 -1
  14. package/dist/array.test.d.ts +2 -0
  15. package/dist/array.test.d.ts.map +1 -1
  16. package/dist/{broadcastchannel-a4555c37.cjs → broadcastchannel-90ed6188.cjs} +2 -2
  17. package/dist/{broadcastchannel-a4555c37.cjs.map → broadcastchannel-90ed6188.cjs.map} +1 -1
  18. package/dist/broadcastchannel.cjs +8 -8
  19. package/dist/{buffer-6e426aed.cjs → buffer-8fda3816.cjs} +6 -6
  20. package/dist/{buffer-6e426aed.cjs.map → buffer-8fda3816.cjs.map} +1 -1
  21. package/dist/buffer.cjs +7 -7
  22. package/dist/cache.cjs +2 -2
  23. package/dist/component.cjs +4 -4
  24. package/dist/{decoding-2c98f95d.cjs → decoding-ec031c24.cjs} +3 -3
  25. package/dist/{decoding-2c98f95d.cjs.map → decoding-ec031c24.cjs.map} +1 -1
  26. package/dist/decoding.cjs +4 -4
  27. package/dist/{diff-2825aafb.cjs → diff-1498c2c4.cjs} +2 -2
  28. package/dist/{diff-2825aafb.cjs.map → diff-1498c2c4.cjs.map} +1 -1
  29. package/dist/diff.cjs +3 -3
  30. package/dist/{encoding-559e49f1.cjs → encoding-8ccbade2.cjs} +3 -3
  31. package/dist/{encoding-559e49f1.cjs.map → encoding-8ccbade2.cjs.map} +1 -1
  32. package/dist/encoding.cjs +3 -3
  33. package/dist/{environment-95824d14.cjs → environment-e0a40d7b.cjs} +3 -3
  34. package/dist/{environment-95824d14.cjs.map → environment-e0a40d7b.cjs.map} +1 -1
  35. package/dist/environment.cjs +4 -4
  36. package/dist/{eventloop-d0571621.cjs → eventloop-b299a889.cjs} +28 -6
  37. package/dist/eventloop-b299a889.cjs.map +1 -0
  38. package/dist/eventloop.cjs +4 -1
  39. package/dist/eventloop.cjs.map +1 -1
  40. package/dist/eventloop.d.ts +1 -1
  41. package/dist/eventloop.d.ts.map +1 -1
  42. package/dist/eventloop.test.d.ts +2 -0
  43. package/dist/eventloop.test.d.ts.map +1 -1
  44. package/dist/{function-932685da.cjs → function-6d805aac.cjs} +2 -2
  45. package/dist/{function-932685da.cjs.map → function-6d805aac.cjs.map} +1 -1
  46. package/dist/function.cjs +2 -2
  47. package/dist/index.cjs +12 -12
  48. package/dist/jwt.cjs +7 -7
  49. package/dist/list.cjs +2 -2
  50. package/dist/logging.cjs +6 -6
  51. package/dist/logging.common.cjs +4 -4
  52. package/dist/logging.node.cjs +4 -4
  53. package/dist/observable.cjs +1 -1
  54. package/dist/performance.node.cjs +2 -2
  55. package/dist/{prng-ffbde921.cjs → prng-af7307f5.cjs} +3 -3
  56. package/dist/{prng-ffbde921.cjs.map → prng-af7307f5.cjs.map} +1 -1
  57. package/dist/prng.cjs +8 -8
  58. package/dist/rabin-gf2-polynomial.cjs +7 -7
  59. package/dist/rabin-uncached.cjs +7 -7
  60. package/dist/rabin.cjs +7 -7
  61. package/dist/{string-d07c212b.cjs → string-95449d68.cjs} +2 -2
  62. package/dist/{string-d07c212b.cjs.map → string-95449d68.cjs.map} +1 -1
  63. package/dist/string.cjs +2 -2
  64. package/dist/testing.cjs +9 -9
  65. package/dist/{websocket-9495c37b.cjs → websocket-cae5df8e.cjs} +1 -1
  66. package/dist/{websocket-9495c37b.cjs.map → websocket-cae5df8e.cjs.map} +1 -1
  67. package/dist/websocket.cjs +2 -2
  68. package/eventloop.d.ts +1 -1
  69. package/eventloop.d.ts.map +1 -1
  70. package/eventloop.js +27 -5
  71. package/eventloop.test.d.ts +2 -0
  72. package/eventloop.test.d.ts.map +1 -1
  73. package/package.json +1 -1
  74. package/test.html +1 -1
  75. package/coverage/tmp/coverage-7197-1742897575185-0.json +0 -1
  76. package/dist/array-8d6422a6.cjs.map +0 -1
  77. package/dist/eventloop-d0571621.cjs.map +0 -1
package/eventloop.js CHANGED
@@ -1,5 +1,7 @@
1
1
  /* global requestIdleCallback, requestAnimationFrame, cancelIdleCallback, cancelAnimationFrame */
2
2
 
3
+ import * as time from './time.js'
4
+
3
5
  /**
4
6
  * Utility module to work with EcmaScript's event loop.
5
7
  *
@@ -93,14 +95,34 @@ export const idleCallback = cb => typeof requestIdleCallback !== 'undefined' ? n
93
95
 
94
96
  /**
95
97
  * @param {number} timeout Timeout of the debounce action
96
- * @return {function(function():void):void}
98
+ * @param {number} triggerAfter Optional. Trigger callback after a certain amount of time
99
+ * without waiting for debounce.
97
100
  */
98
- export const createDebouncer = timeout => {
101
+ export const createDebouncer = (timeout, triggerAfter = -1) => {
99
102
  let timer = -1
100
- return f => {
103
+ /**
104
+ * @type {number?}
105
+ */
106
+ let lastCall = null
107
+ /**
108
+ * @param {((...args: any)=>void)?} cb function to trigger after debounce. If null, it will reset the
109
+ * debounce.
110
+ */
111
+ return cb => {
101
112
  clearTimeout(timer)
102
- if (f) {
103
- timer = /** @type {any} */ (setTimeout(f, timeout))
113
+ if (cb) {
114
+ if (triggerAfter >= 0) {
115
+ const now = time.getUnixTime()
116
+ if (lastCall === null) lastCall = now
117
+ if (now - lastCall > triggerAfter) {
118
+ lastCall = null
119
+ timer = /** @type {any} */ (setTimeout(cb, 0))
120
+ return
121
+ }
122
+ }
123
+ timer = /** @type {any} */ (setTimeout(() => { lastCall = null; cb() }, timeout))
124
+ } else {
125
+ lastCall = null
104
126
  }
105
127
  }
106
128
  }
@@ -4,5 +4,7 @@ export function testInterval(_tc: t.TestCase): Promise<void>;
4
4
  export function testAnimationFrame(_tc: t.TestCase): Promise<void>;
5
5
  export function testIdleCallback(_tc: t.TestCase): Promise<void>;
6
6
  export function testDebouncer(_tc: t.TestCase): Promise<void>;
7
+ export function testDebouncerTriggerAfter(_tc: t.TestCase): Promise<void>;
8
+ export function testDebouncerClear(_tc: t.TestCase): Promise<void>;
7
9
  import * as t from './testing.js';
8
10
  //# sourceMappingURL=eventloop.test.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventloop.test.d.ts","sourceRoot":"","sources":["eventloop.test.js"],"names":[],"mappings":"AAOO,wCAFI,EAAE,QAAQ,yBAkBpB;AAKM,iCAFI,EAAE,QAAQ,iBAYpB;AAKM,kCAFI,EAAE,QAAQ,iBAepB;AAKM,wCAFI,EAAE,QAAQ,iBAOpB;AAKM,sCAFI,EAAE,QAAQ,iBAMpB;AAKM,mCAFI,EAAE,QAAQ,iBAcpB;mBA3FkB,cAAc"}
1
+ {"version":3,"file":"eventloop.test.d.ts","sourceRoot":"","sources":["eventloop.test.js"],"names":[],"mappings":"AAOO,wCAFI,EAAE,QAAQ,yBAkBpB;AAKM,iCAFI,EAAE,QAAQ,iBAYpB;AAKM,kCAFI,EAAE,QAAQ,iBAepB;AAKM,wCAFI,EAAE,QAAQ,iBAOpB;AAKM,sCAFI,EAAE,QAAQ,iBAMpB;AAKM,mCAFI,EAAE,QAAQ,iBAcpB;AAKM,+CAFI,EAAE,QAAQ,iBAyBpB;AAKM,wCAFI,EAAE,QAAQ,iBAyBpB;mBAnJkB,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "0.2.101",
3
+ "version": "0.2.103",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "type": "module",
package/test.html CHANGED
@@ -28,7 +28,7 @@
28
28
  "lib0/component": "./component.js",
29
29
  "lib0/conditions.js": "./conditions.js",
30
30
  "lib0/dist/conditions.cjs": "./dist/conditions.cjs",
31
- "lib0/conditions": "./condititons.js",
31
+ "lib0/conditions": "./conditions.js",
32
32
  "lib0/crypto/jwt": "./crypto/jwt.js",
33
33
  "lib0/crypto/aes-gcm": "./crypto/aes-gcm.js",
34
34
  "lib0/crypto/ecdsa": "./crypto/ecdsa.js",