anu-verzum 2.2.9 → 2.3.0

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.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  A lightweight React-inspired UI library for building component-based web applications in JavaScript and TypeScript.
11
11
 
12
- - Fiber-based virtual DOM with time-sliced rendering (`requestIdleCallback`)
12
+ - Fiber-based virtual DOM with time-sliced rendering (MessageChannel scheduler)
13
13
  - Class components with full lifecycle support and function components
14
14
  - JSX via a custom Babel preset — no separate TypeScript preset needed
15
15
  - Redux-compatible state management with thunk middleware and memoized selectors
@@ -6,5 +6,7 @@ export declare const render: (elements: AnuElement | AnuElement[], containerDom:
6
6
  export declare const unmountComponentAtNode: (containerDom: Element) => void;
7
7
  export declare const __testing: {
8
8
  flushSync(): void;
9
+ installSyncScheduler(): void;
10
+ uninstallSyncScheduler(): void;
9
11
  resetGlobals(): void;
10
12
  };
@@ -61,9 +61,50 @@ const workLoop = deadline => {
61
61
  const performWork = deadline => {
62
62
  workLoop(deadline);
63
63
  if (nextUnitOfWork || updateQueue.length > 0) {
64
- requestIdleCallback(performWork);
64
+ scheduleWork();
65
65
  }
66
66
  };
67
+ const FRAME_BUDGET = 5;
68
+ const now = () => typeof performance !== 'undefined' && typeof performance.now === 'function' ? performance.now() : Date.now();
69
+ let frameDeadline = 0;
70
+ const FRAME_DEADLINE = {
71
+ didTimeout: false,
72
+ timeRemaining: () => Math.max(0, frameDeadline - now())
73
+ };
74
+ const SYNC_DEADLINE = {
75
+ didTimeout: false,
76
+ timeRemaining: () => 999
77
+ };
78
+ const createMacroTaskScheduler = () => {
79
+ let scheduled = false;
80
+ const flush = () => {
81
+ scheduled = false;
82
+ frameDeadline = now() + FRAME_BUDGET;
83
+ performWork(FRAME_DEADLINE);
84
+ };
85
+ let post;
86
+ if (typeof MessageChannel !== 'undefined') {
87
+ const channel = new MessageChannel();
88
+ channel.port1.onmessage = flush;
89
+ post = () => channel.port2.postMessage(null);
90
+ } else {
91
+ post = () => {
92
+ setTimeout(flush, 0);
93
+ };
94
+ }
95
+ return () => {
96
+ if (scheduled) {
97
+ return;
98
+ }
99
+ scheduled = true;
100
+ post();
101
+ };
102
+ };
103
+ const defaultScheduleWork = createMacroTaskScheduler();
104
+ const syncScheduleWork = () => {
105
+ performWork(SYNC_DEADLINE);
106
+ };
107
+ let scheduleWork = defaultScheduleWork;
67
108
  const performUnitOfWork = wipFiber => {
68
109
  beginWork(wipFiber);
69
110
  if (wipFiber.child) {
@@ -467,7 +508,7 @@ const scheduleUpdate = (instance, partialState, partialStateCallback) => {
467
508
  updateFiber.partialStateCallback = partialStateCallback;
468
509
  }
469
510
  updateQueue.push(updateFiber);
470
- requestIdleCallback(performWork);
511
+ scheduleWork();
471
512
  };
472
513
  exports.scheduleUpdate = scheduleUpdate;
473
514
  const render = (elements, containerDom) => {
@@ -478,7 +519,7 @@ const render = (elements, containerDom) => {
478
519
  children: Array.isArray(elements) ? elements : [elements]
479
520
  }
480
521
  });
481
- requestIdleCallback(performWork);
522
+ scheduleWork();
482
523
  };
483
524
  exports.render = render;
484
525
  const unmountComponentAtNode = containerDom => {
@@ -492,7 +533,7 @@ const unmountComponentAtNode = containerDom => {
492
533
  children: []
493
534
  }
494
535
  });
495
- requestIdleCallback(performWork);
536
+ scheduleWork();
496
537
  };
497
538
  exports.unmountComponentAtNode = unmountComponentAtNode;
498
539
  const __testing = exports.__testing = {
@@ -500,16 +541,24 @@ const __testing = exports.__testing = {
500
541
  if (process.env.NODE_ENV !== 'test') {
501
542
  return;
502
543
  }
503
- const syncDeadline = {
504
- didTimeout: false,
505
- timeRemaining: () => 999
506
- };
507
544
  while (updateQueue.length > 0 || nextUnitOfWork != null) {
508
- workLoop(syncDeadline);
545
+ workLoop(SYNC_DEADLINE);
509
546
  }
510
547
  nextUnitOfWork = null;
511
548
  pendingCommit = null;
512
549
  },
550
+ installSyncScheduler() {
551
+ if (process.env.NODE_ENV !== 'test') {
552
+ return;
553
+ }
554
+ scheduleWork = syncScheduleWork;
555
+ },
556
+ uninstallSyncScheduler() {
557
+ if (process.env.NODE_ENV !== 'test') {
558
+ return;
559
+ }
560
+ scheduleWork = defaultScheduleWork;
561
+ },
513
562
  resetGlobals() {
514
563
  if (process.env.NODE_ENV !== 'test') {
515
564
  return;
package/dist/index.js CHANGED
@@ -121,22 +121,6 @@ var _Intl = _interopRequireDefault(require("./core/components/Intl"));
121
121
  var _AnulyticsProvider = _interopRequireWildcard(require("./core/components/AnulyticsProvider"));
122
122
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
123
123
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
124
- if (!window.requestIdleCallback) {
125
- window.requestIdleCallback = callback => {
126
- const start = Date.now();
127
- return setTimeout(() => {
128
- callback({
129
- didTimeout: false,
130
- timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
131
- });
132
- }, 1);
133
- };
134
- }
135
- if (!window.cancelIdleCallback) {
136
- window.cancelIdleCallback = id => {
137
- clearTimeout(id);
138
- };
139
- }
140
124
  const Anu = {
141
125
  Anulytics: {
142
126
  Provider: _AnulyticsProvider.default,
@@ -5,25 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.uninstallSyncScheduler = exports.installSyncScheduler = exports.flushEffects = exports.act = void 0;
7
7
  var _reconciler = require("../core/reconciler");
8
- const FAKE_DEADLINE = {
9
- didTimeout: false,
10
- timeRemaining: () => 999
11
- };
12
8
  let _installed = false;
13
9
  const installSyncScheduler = () => {
14
10
  if (_installed) {
15
11
  return;
16
12
  }
17
13
  _installed = true;
18
- window.requestIdleCallback = cb => {
19
- cb(FAKE_DEADLINE);
20
- return 0;
21
- };
22
- window.cancelIdleCallback = () => {};
14
+ _reconciler.__testing.installSyncScheduler();
23
15
  };
24
16
  exports.installSyncScheduler = installSyncScheduler;
25
17
  const uninstallSyncScheduler = () => {
26
18
  _installed = false;
19
+ _reconciler.__testing.uninstallSyncScheduler();
27
20
  };
28
21
  exports.uninstallSyncScheduler = uninstallSyncScheduler;
29
22
  const flushEffects = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anu-verzum",
3
- "version": "2.2.9",
3
+ "version": "2.3.0",
4
4
  "description": "A \"React-like\" UI library that supports JSX syntax, Redux-like state management, array-rendering, i18n, routing and many more.",
5
5
  "keywords": [
6
6
  "anu-verzum",