anu-verzum 2.2.8 → 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,7 +6,7 @@ export declare abstract class Component<P extends Record<string, any> = Props, S
6
6
  __fiber?: any;
7
7
  static isAnuComponent: boolean;
8
8
  constructor(props: P, context?: Record<string, any>);
9
- setState(partialState?: Partial<S> | ((prevState: S, prevProps: P) => S)): void;
9
+ setState(partialState?: Partial<S> | ((prevState: S, prevProps: P) => Partial<S>)): void;
10
10
  abstract render(): AnuElement | AnuElement[] | string | number | boolean | null | undefined;
11
11
  componentDidMount(): void;
12
12
  componentDidUpdate(_prevProps: P, _prevState: S): void;
@@ -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) {
@@ -150,12 +191,8 @@ const updateClassComponent = wipFiber => {
150
191
  cloneChildFibers(wipFiber);
151
192
  return;
152
193
  }
153
- let nextState;
154
- if (!wipFiber.partialStateCallback) {
155
- nextState = Object.assign({}, instance.state, wipFiber.partialState);
156
- } else {
157
- nextState = wipFiber.partialStateCallback(instance.state, wipFiber.props);
158
- }
194
+ const statePatch = wipFiber.partialStateCallback ? wipFiber.partialStateCallback(instance.state, wipFiber.props) : wipFiber.partialState;
195
+ const nextState = Object.assign({}, instance.state, statePatch);
159
196
  wipFiber.prevState = {
160
197
  ...instance.state
161
198
  };
@@ -471,7 +508,7 @@ const scheduleUpdate = (instance, partialState, partialStateCallback) => {
471
508
  updateFiber.partialStateCallback = partialStateCallback;
472
509
  }
473
510
  updateQueue.push(updateFiber);
474
- requestIdleCallback(performWork);
511
+ scheduleWork();
475
512
  };
476
513
  exports.scheduleUpdate = scheduleUpdate;
477
514
  const render = (elements, containerDom) => {
@@ -482,7 +519,7 @@ const render = (elements, containerDom) => {
482
519
  children: Array.isArray(elements) ? elements : [elements]
483
520
  }
484
521
  });
485
- requestIdleCallback(performWork);
522
+ scheduleWork();
486
523
  };
487
524
  exports.render = render;
488
525
  const unmountComponentAtNode = containerDom => {
@@ -496,7 +533,7 @@ const unmountComponentAtNode = containerDom => {
496
533
  children: []
497
534
  }
498
535
  });
499
- requestIdleCallback(performWork);
536
+ scheduleWork();
500
537
  };
501
538
  exports.unmountComponentAtNode = unmountComponentAtNode;
502
539
  const __testing = exports.__testing = {
@@ -504,16 +541,24 @@ const __testing = exports.__testing = {
504
541
  if (process.env.NODE_ENV !== 'test') {
505
542
  return;
506
543
  }
507
- const syncDeadline = {
508
- didTimeout: false,
509
- timeRemaining: () => 999
510
- };
511
544
  while (updateQueue.length > 0 || nextUnitOfWork != null) {
512
- workLoop(syncDeadline);
545
+ workLoop(SYNC_DEADLINE);
513
546
  }
514
547
  nextUnitOfWork = null;
515
548
  pendingCommit = null;
516
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
+ },
517
562
  resetGlobals() {
518
563
  if (process.env.NODE_ENV !== 'test') {
519
564
  return;
package/dist/index.d.ts CHANGED
@@ -43,7 +43,7 @@ declare const Anu: {
43
43
  state: Record<string, any>;
44
44
  context: Record<string, any>;
45
45
  __fiber?: any;
46
- setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/Feature").FeatureToggleProps) => Record<string, any>)): void;
46
+ setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/Feature").FeatureToggleProps) => Partial<Record<string, any>>)): void;
47
47
  componentDidMount(): void;
48
48
  componentDidUpdate(_prevProps: import("./core/components/Feature").FeatureToggleProps, _prevState: Record<string, any>): void;
49
49
  componentWillUnmount(): void;
@@ -61,7 +61,7 @@ declare const Anu: {
61
61
  state: Record<string, any>;
62
62
  context: Record<string, any>;
63
63
  __fiber?: any;
64
- setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/History").HistoryLinkProps) => Record<string, any>)): void;
64
+ setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/History").HistoryLinkProps) => Partial<Record<string, any>>)): void;
65
65
  componentDidMount(): void;
66
66
  componentDidUpdate(_prevProps: import("./core/components/History").HistoryLinkProps, _prevState: Record<string, any>): void;
67
67
  componentWillUnmount(): void;
@@ -76,7 +76,7 @@ declare const Anu: {
76
76
  state: Record<string, any>;
77
77
  context: Record<string, any>;
78
78
  __fiber?: any;
79
- setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/History").HistoryRedirectProps) => Record<string, any>)): void;
79
+ setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/History").HistoryRedirectProps) => Partial<Record<string, any>>)): void;
80
80
  componentDidUpdate(_prevProps: import("./core/components/History").HistoryRedirectProps, _prevState: Record<string, any>): void;
81
81
  componentWillUnmount(): void;
82
82
  };
@@ -92,7 +92,7 @@ declare const Anu: {
92
92
  state: Record<string, any>;
93
93
  context: Record<string, any>;
94
94
  __fiber?: any;
95
- setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/History").HistoryRouteProps) => Record<string, any>)): void;
95
+ setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/History").HistoryRouteProps) => Partial<Record<string, any>>)): void;
96
96
  componentDidUpdate(_prevProps: import("./core/components/History").HistoryRouteProps, _prevState: Record<string, any>): void;
97
97
  };
98
98
  isAnuComponent: boolean;
@@ -123,7 +123,7 @@ declare const Anu: {
123
123
  state: Record<string, any>;
124
124
  context: Record<string, any>;
125
125
  __fiber?: any;
126
- setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/Connector").ConnectorProviderProps) => Record<string, any>)): void;
126
+ setState(partialState?: Partial<Record<string, any>> | ((prevState: Record<string, any>, prevProps: import("./core/components/Connector").ConnectorProviderProps) => Partial<Record<string, any>>)): void;
127
127
  componentDidMount(): void;
128
128
  componentDidUpdate(_prevProps: import("./core/components/Connector").ConnectorProviderProps, _prevState: Record<string, any>): void;
129
129
  componentWillUnmount(): void;
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 = () => {
@@ -15,6 +15,11 @@ export declare const fireEvent: {
15
15
  submit(el: Element, init?: EventInit): boolean;
16
16
  mouseDown(el: Element, init?: EventInit): boolean;
17
17
  mouseUp(el: Element, init?: EventInit): boolean;
18
+ mouseEnter(el: Element, init?: EventInit): boolean;
19
+ mouseLeave(el: Element, init?: EventInit): boolean;
20
+ mouseOver(el: Element, init?: EventInit): boolean;
21
+ mouseOut(el: Element, init?: EventInit): boolean;
22
+ mouseMove(el: Element, init?: EventInit): boolean;
18
23
  wheel(el: Element, init?: EventInit): boolean;
19
24
  error(el: Element, init?: EventInit): boolean;
20
25
  load(el: Element, init?: EventInit): boolean;
@@ -53,6 +53,11 @@ fireEvent.keyPress = (el, init) => fireEvent(el, 'keypress', init);
53
53
  fireEvent.submit = (el, init) => fireEvent(el, 'submit', init);
54
54
  fireEvent.mouseDown = (el, init) => fireEvent(el, 'mousedown', init);
55
55
  fireEvent.mouseUp = (el, init) => fireEvent(el, 'mouseup', init);
56
+ fireEvent.mouseEnter = (el, init) => fireEvent(el, 'mouseenter', init);
57
+ fireEvent.mouseLeave = (el, init) => fireEvent(el, 'mouseleave', init);
58
+ fireEvent.mouseOver = (el, init) => fireEvent(el, 'mouseover', init);
59
+ fireEvent.mouseOut = (el, init) => fireEvent(el, 'mouseout', init);
60
+ fireEvent.mouseMove = (el, init) => fireEvent(el, 'mousemove', init);
56
61
  fireEvent.wheel = (el, init) => fireEvent(el, 'wheel', init);
57
62
  fireEvent.error = (el, init) => fireEvent(el, 'error', init);
58
63
  fireEvent.load = (el, init) => fireEvent(el, 'load', init);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anu-verzum",
3
- "version": "2.2.8",
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",