lilact 0.31.4 → 0.31.6

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 (31) hide show
  1. package/dist/lilact.development.js +25 -24
  2. package/dist/lilact.development.js.map +2 -2
  3. package/dist/lilact.development.min.js +19 -19
  4. package/dist/lilact.development.min.js.map +2 -2
  5. package/dist/lilact.production.min.js +20 -20
  6. package/docs/functions/timers.animationFramePromise.html +1 -1
  7. package/docs/functions/timers.clearInterval.html +1 -1
  8. package/docs/functions/timers.clearTimeout.html +1 -1
  9. package/docs/functions/timers.grabTimers.html +1 -1
  10. package/docs/functions/timers.pauseTimers.html +1 -1
  11. package/docs/functions/timers.releaseTimers.html +1 -1
  12. package/docs/functions/timers.resetTimers.html +1 -1
  13. package/docs/functions/timers.resumeTimers.html +1 -1
  14. package/docs/functions/timers.setInterval.html +1 -1
  15. package/docs/functions/timers.setTimeout.html +1 -1
  16. package/docs/functions/timers.timeoutPromise.html +1 -1
  17. package/docs/static/lilact.development.js +25 -24
  18. package/docs/static/lilact.development.js.map +2 -2
  19. package/docs/static/lilact.development.min.js +19 -19
  20. package/docs/static/lilact.development.min.js.map +2 -2
  21. package/docs/static/lilact.production.min.js +20 -20
  22. package/examples/lilact.development.js +25 -24
  23. package/examples/lilact.development.js.map +2 -2
  24. package/examples/lilact.development.min.js +19 -19
  25. package/examples/lilact.development.min.js.map +2 -2
  26. package/examples/lilact.production.min.js +20 -20
  27. package/package.json +1 -1
  28. package/src/components.jsx +2 -2
  29. package/src/hooks.jsx +6 -6
  30. package/src/lilact.jsx +0 -6
  31. package/src/timers.jsx +29 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lilact",
3
- "version": "0.31.4",
3
+ "version": "0.31.6",
4
4
  "description": "A Little React/JSX Runtime Implementation for Browser",
5
5
  "repository": "github:arashkazemi/lilact",
6
6
  "homepage": "https://arashkazemi.github.io/lilact/",
@@ -1214,11 +1214,11 @@ export class Component
1214
1214
  */
1215
1215
  forceUpdate(callback)
1216
1216
  {
1217
- Lilact._clearTimeout(Lilact.update_timeout);
1217
+ NATIVE_TIMERS.clearTimeout(Lilact.update_timeout);
1218
1218
 
1219
1219
  Lilact.update_set.add(this[CORE].container || this[CORE]);
1220
1220
  if(callback) Lilact.update_cbs.add(callback.bind(this));
1221
- Lilact.update_timeout = Lilact._setTimeout( doUpdates, Lilact.update_interval_margin );
1221
+ Lilact.update_timeout = NATIVE_TIMERS.setTimeout( doUpdates, Lilact.update_interval_margin );
1222
1222
  }
1223
1223
 
1224
1224
  /**
package/src/hooks.jsx CHANGED
@@ -294,8 +294,8 @@ export async function useLayoutEffect(effect, deps=undefined)
294
294
  hk.deps = deps;
295
295
  Lilact.layout_effects.add( async ()=>{ hk.cleanup = await effect(); });
296
296
 
297
- Lilact._clearTimeout( Lilact.effect_timeout );
298
- Lilact._setTimeout( Lilact.processEffects, 0 );
297
+ NATIVE_TIMERS.clearTimeout( Lilact.effect_timeout );
298
+ Lilact.effect_timeout = NATIVE_TIMERS.setTimeout( Lilact.processEffects, 0 );
299
299
  }
300
300
 
301
301
  /**
@@ -330,8 +330,8 @@ export async function useEffect(effect, deps=undefined)
330
330
  hk.deps = deps;
331
331
  Lilact.passive_effects.add( async ()=>{ hk.cleanup = await effect(); });
332
332
 
333
- Lilact._clearTimeout( Lilact.effect_timeout );
334
- Lilact._setTimeout( Lilact.processEffects, 0 );
333
+ NATIVE_TIMERS.clearTimeout( Lilact.effect_timeout );
334
+ Lilact.effect_timeout = NATIVE_TIMERS.setTimeout( Lilact.processEffects, 0 );
335
335
  }
336
336
 
337
337
 
@@ -367,8 +367,8 @@ export async function useInsertionEffect(effect, deps=undefined)
367
367
  hk.deps = deps;
368
368
  Lilact.insertion_effects.add( async ()=>{ hk.cleanup = await effect(); });
369
369
 
370
- Lilact._clearTimeout( Lilact.effect_timeout );
371
- Lilact._setTimeout( Lilact.processEffects, 0 );
370
+ NATIVE_TIMERS.clearTimeout( Lilact.effect_timeout );
371
+ Lilact.effect_timeout = NATIVE_TIMERS.setTimeout( Lilact.processEffects, 0 );
372
372
  }
373
373
 
374
374
 
package/src/lilact.jsx CHANGED
@@ -125,12 +125,6 @@ export const Lilact =
125
125
  PropTypes,
126
126
  redux,
127
127
  emotion,
128
-
129
- _setTimeout: globalThis.setTimeout.bind(globalThis),
130
- _setInterval: globalThis.setInterval.bind(globalThis),
131
- _clearTimeout: globalThis.clearTimeout.bind(globalThis),
132
- _clearInterval: globalThis.clearInterval.bind(globalThis),
133
-
134
128
  }
135
129
 
136
130
  Lilact.default = Lilact;
package/src/timers.jsx CHANGED
@@ -47,16 +47,21 @@ import {
47
47
  * Managed timers can be paused, resumed, reset, or released. Promise-based
48
48
  * helpers are also provided through `timeoutPromise` and
49
49
  * `animationFramePromise`.
50
- *
51
- * The `Lilact._setTimeout`, `Lilact._setInterval`, `Lilact._clearTimeout`,
52
- * and `Lilact._clearInterval` properties must reference the original native
53
- * timer functions.
54
50
  */
55
51
 
56
52
  let timer_pause_time;
57
53
  let current_timer_idx = 0;
58
54
  let timer_list = [];
59
55
  let timer_timeout = 0;
56
+
57
+
58
+ globalThis.NATIVE_TIMERS ??= {};
59
+
60
+ NATIVE_TIMERS.setTimeout ??= globalThis.setTimeout.bind(globalThis);
61
+ NATIVE_TIMERS.setInterval ??= globalThis.setInterval.bind(globalThis);
62
+ NATIVE_TIMERS.clearTimeout ??= globalThis.clearTimeout.bind(globalThis);
63
+ NATIVE_TIMERS.clearInterval ??= globalThis.clearInterval.bind(globalThis);
64
+
60
65
  let all_timers = new Map();
61
66
 
62
67
  /**
@@ -105,14 +110,14 @@ function schedule_next_timer() {
105
110
  return;
106
111
  }
107
112
 
108
- Lilact._clearTimeout(timer_timeout);
113
+ NATIVE_TIMERS.clearTimeout(timer_timeout);
109
114
 
110
115
  const delay = Math.max(
111
116
  0,
112
117
  timer_list[0][DUE] - Date.now()
113
118
  );
114
119
 
115
- timer_timeout = Lilact._setTimeout(run_timer, delay);
120
+ timer_timeout = NATIVE_TIMERS.setTimeout(run_timer, delay);
116
121
  }
117
122
 
118
123
  function add_timer(timer, is_repeat = false) {
@@ -229,7 +234,7 @@ function run_timer() {
229
234
  * completed.
230
235
  */
231
236
  if (first_error !== undefined) {
232
- Lilact._setTimeout(() => {
237
+ NATIVE_TIMERS.setTimeout(() => {
233
238
  throw first_error;
234
239
  }, 0);
235
240
  }
@@ -245,7 +250,7 @@ function run_timer() {
245
250
  * @returns {void}
246
251
  */
247
252
  export function resetTimers() {
248
- Lilact._clearTimeout(timer_timeout);
253
+ NATIVE_TIMERS.clearTimeout(timer_timeout);
249
254
 
250
255
  for (const timer of all_timers.values()) {
251
256
  timer[CLEARED] = true;
@@ -274,7 +279,7 @@ export function pauseTimers() {
274
279
  return;
275
280
  }
276
281
 
277
- Lilact._clearTimeout(timer_timeout);
282
+ NATIVE_TIMERS.clearTimeout(timer_timeout);
278
283
  timer_timeout = -1;
279
284
  timer_pause_time = Date.now();
280
285
  }
@@ -367,7 +372,7 @@ export function clearTimeout(id) {
367
372
  if (timer !== undefined) {
368
373
  timer[CLEARED] = true;
369
374
  } else {
370
- Lilact._clearTimeout(id);
375
+ NATIVE_TIMERS.clearTimeout(id);
371
376
  }
372
377
  }
373
378
 
@@ -381,13 +386,14 @@ export function clearTimeout(id) {
381
386
  * @param {number} id - Interval ID returned by `setInterval`.
382
387
  * @returns {void}
383
388
  */
384
- export function clearInterval(id) {
389
+ export function clearInterval(id)
390
+ {
385
391
  const timer = all_timers.get(id);
386
392
 
387
393
  if (timer !== undefined) {
388
394
  timer[CLEARED] = true;
389
395
  } else {
390
- Lilact._clearInterval(id);
396
+ NATIVE_TIMERS.clearInterval(id);
391
397
  }
392
398
  }
393
399
 
@@ -400,7 +406,8 @@ export function clearInterval(id) {
400
406
  *
401
407
  * @returns {void}
402
408
  */
403
- export function grabTimers() {
409
+ export function grabTimers()
410
+ {
404
411
  globalThis.setTimeout = Lilact.setTimeout;
405
412
  globalThis.setInterval = Lilact.setInterval;
406
413
  globalThis.clearTimeout = Lilact.clearTimeout;
@@ -415,11 +422,12 @@ export function grabTimers() {
415
422
  *
416
423
  * @returns {void}
417
424
  */
418
- export function releaseTimers() {
419
- globalThis.setTimeout = Lilact._setTimeout;
420
- globalThis.setInterval = Lilact._setInterval;
421
- globalThis.clearTimeout = Lilact._clearTimeout;
422
- globalThis.clearInterval = Lilact._clearInterval;
425
+ export function releaseTimers()
426
+ {
427
+ globalThis.setTimeout = NATIVE_TIMERS.setTimeout;
428
+ globalThis.setInterval = NATIVE_TIMERS.setInterval;
429
+ globalThis.clearTimeout = NATIVE_TIMERS.clearTimeout;
430
+ globalThis.clearInterval = NATIVE_TIMERS.clearInterval;
423
431
  }
424
432
 
425
433
  /**
@@ -434,7 +442,8 @@ export function releaseTimers() {
434
442
  * @param {Object} [timerSource=Lilact] - Object providing timer functions.
435
443
  * @returns {Promise} Promise that resolves after the timeout.
436
444
  */
437
- export function timeoutPromise(duration = 0, timerSource = Lilact) {
445
+ export function timeoutPromise(duration = 0, timerSource = Lilact)
446
+ {
438
447
  let id;
439
448
  let resolve_promise;
440
449
  let reject_promise;
@@ -483,3 +492,4 @@ export function animationFramePromise() {
483
492
  });
484
493
  });
485
494
  }
495
+