@simpreact/simpreact 0.0.7 → 0.0.9

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 (81) hide show
  1. package/compat/context.js +3 -3
  2. package/compat/core.js +105 -18
  3. package/compat/dom.js +5 -5
  4. package/compat/hooks.js +18 -3
  5. package/compat/index.d.ts +109 -45
  6. package/compat/jsx-runtime.js +4 -4
  7. package/compat/renderRuntime.js +47 -12
  8. package/component/index.d.ts +6 -7
  9. package/component/index.js +96 -94
  10. package/context/index.d.ts +5 -5
  11. package/context/index.js +27 -17
  12. package/core/createElement.js +14 -17
  13. package/core/flags.js +31 -0
  14. package/core/hostOperations.js +5 -13
  15. package/core/index.d.ts +48 -11
  16. package/core/index.js +4 -2
  17. package/core/internal.d.ts +136 -16
  18. package/core/internal.js +8 -16
  19. package/core/lifecycleEventBus.js +35 -16
  20. package/core/memo.js +4 -1
  21. package/core/mounting.js +70 -150
  22. package/core/mountingChildren.js +11 -29
  23. package/core/patching.js +122 -181
  24. package/core/patchingChildren.js +74 -145
  25. package/core/portal.js +1 -1
  26. package/core/processStack.js +115 -45
  27. package/core/ref.js +1 -0
  28. package/core/rerender.js +20 -22
  29. package/core/runtime.js +10 -2
  30. package/core/unmounting.js +41 -49
  31. package/core/unmountingChildren.js +9 -12
  32. package/core/utils.js +38 -16
  33. package/dom/attach-element-to-dom.js +16 -8
  34. package/dom/events.js +11 -15
  35. package/dom/index.d.ts +6 -5
  36. package/dom/props/attrMaps.js +90 -0
  37. package/dom/props/controlled/select.js +8 -10
  38. package/dom/props/props.js +13 -14
  39. package/hooks/index.d.ts +15 -10
  40. package/hooks/index.js +107 -84
  41. package/package.json +10 -5
  42. package/shared/index.d.ts +10 -6
  43. package/compat/context.d.ts +0 -8
  44. package/compat/core.d.ts +0 -47
  45. package/compat/dom.d.ts +0 -10
  46. package/compat/hooks.d.ts +0 -27
  47. package/compat/jsx-runtime.d.ts +0 -10
  48. package/compat/renderRuntime.d.ts +0 -6
  49. package/core/createElement.d.ts +0 -39
  50. package/core/fragment.d.ts +0 -5
  51. package/core/hostAdapter.d.ts +0 -23
  52. package/core/hostOperations.d.ts +0 -5
  53. package/core/lifecycleEventBus.d.ts +0 -39
  54. package/core/memo.d.ts +0 -8
  55. package/core/mounting.d.ts +0 -7
  56. package/core/mountingChildren.d.ts +0 -4
  57. package/core/patching.d.ts +0 -8
  58. package/core/patchingChildren.d.ts +0 -6
  59. package/core/portal.d.ts +0 -2
  60. package/core/processStack.d.ts +0 -106
  61. package/core/ref.d.ts +0 -18
  62. package/core/rerender.d.ts +0 -4
  63. package/core/runtime.d.ts +0 -17
  64. package/core/unmounting.d.ts +0 -7
  65. package/core/unmountingChildren.d.ts +0 -4
  66. package/core/utils.d.ts +0 -11
  67. package/dom/attach-element-to-dom.d.ts +0 -5
  68. package/dom/domAdapter.d.ts +0 -3
  69. package/dom/events.d.ts +0 -27
  70. package/dom/namespace.d.ts +0 -2
  71. package/dom/props/controlled/index.d.ts +0 -7
  72. package/dom/props/controlled/input.d.ts +0 -7
  73. package/dom/props/controlled/select.d.ts +0 -6
  74. package/dom/props/controlled/textarea.d.ts +0 -6
  75. package/dom/props/dangerInnerHTML.d.ts +0 -7
  76. package/dom/props/index.d.ts +0 -1
  77. package/dom/props/props.d.ts +0 -5
  78. package/dom/props/style.d.ts +0 -1
  79. package/dom/render.d.ts +0 -8
  80. package/shared/lang.d.ts +0 -3
  81. package/shared/utils.d.ts +0 -5
@@ -1,16 +1,136 @@
1
- export * from './createElement.js';
2
- export * from './fragment.js';
3
- export * from './hostAdapter.js';
4
- export * from './lifecycleEventBus.js';
5
- export * from './memo.js';
6
- export * from './mounting.js';
7
- export * from './mountingChildren.js';
8
- export * from './patching.js';
9
- export * from './patchingChildren.js';
10
- export * from './portal.js';
11
- export * from './processStack.js';
12
- export * from './ref.js';
13
- export * from './rerender.js';
14
- export * from './runtime.js';
15
- export * from './unmounting.js';
16
- export * from './unmountingChildren.js';
1
+ import type { Many, Maybe, Nullable } from '../shared/index.js';
2
+
3
+ export type FC = (props: any) => SimpNode;
4
+ export type Key = string | number | bigint;
5
+ export type SimpNode = SimpElement | string | number | bigint | boolean | Array<SimpNode> | null | undefined;
6
+
7
+ export interface SimpElement {
8
+ flag: number;
9
+ childFlag: number;
10
+ parent: Nullable<SimpElement>;
11
+ key: Nullable<Key>;
12
+ type: Nullable<string | FC>;
13
+ props: any;
14
+ children: SimpNode;
15
+ className: Nullable<string>;
16
+ reference: unknown;
17
+ hostNamespace: Nullable<string>;
18
+ context: any;
19
+ ref: any;
20
+ unmounted: Nullable<boolean>;
21
+ index: number;
22
+ }
23
+
24
+ export type RefObject<T> = { current: T };
25
+
26
+ export interface HostAdapter<HostRef = unknown, HostTextRef = unknown, NS = string> {
27
+ createReference(type: string, namespace?: Maybe<NS>): HostRef;
28
+ createTextReference(text: string): HostTextRef;
29
+ mountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime, namespace?: Maybe<NS>): void;
30
+ patchProps(
31
+ reference: HostRef,
32
+ prevElement: SimpElement,
33
+ nextElement: SimpElement,
34
+ renderRuntime: SimpRenderRuntime,
35
+ namespace?: Maybe<NS>
36
+ ): void;
37
+ unmountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime): void;
38
+ setClassname(reference: HostRef, className: Maybe<string>, namespace?: Maybe<NS>): void;
39
+ setTextContent(reference: HostRef, text: string, referenceHasOnlyTextElement?: boolean): void;
40
+ removeChild(parent: HostRef, child: HostRef | HostTextRef): void;
41
+ replaceChild(parent: HostRef, replacer: HostRef | HostTextRef, toBeReplaced: HostRef | HostTextRef): void;
42
+ insertOrAppend(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
43
+ clearNode(reference: HostRef | HostTextRef): void;
44
+ attachElementToReference(
45
+ element: SimpElement,
46
+ reference: HostRef | HostTextRef,
47
+ renderRuntime: SimpRenderRuntime
48
+ ): void;
49
+ detachElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): void;
50
+ getElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): Nullable<SimpElement>;
51
+ getHostNamespaces(
52
+ element: SimpElement,
53
+ currentNamespace: Maybe<NS>
54
+ ): Nullable<{ self: Nullable<NS>; children: Nullable<NS> }>;
55
+ }
56
+
57
+ export interface SimpRuntimeFCRenderer {
58
+ (component: FC, element: SimpElement, renderRuntime: SimpRenderRuntime): SimpNode;
59
+ }
60
+
61
+ export interface SimpRenderFrame {
62
+ kind: number;
63
+ node: SimpElement;
64
+ renderRuntime: SimpRenderRuntime;
65
+ parentReference: unknown;
66
+ subtreeRightBoundary: Nullable<SimpElement>;
67
+ context: unknown;
68
+ hostNamespace: Maybe<string>;
69
+ prevElement: SimpElement;
70
+ children: Nullable<Many<SimpElement>>;
71
+ placeHolderElement: Nullable<SimpElement>;
72
+ }
73
+
74
+ export interface SimpRenderRuntime {
75
+ hostAdapter: HostAdapter;
76
+ renderer: SimpRuntimeFCRenderer;
77
+ renderStack: Array<any>;
78
+ framePool: SimpRenderFrame[];
79
+ activeRenderElement: SimpElement | null;
80
+ pendingRerenderFlag: boolean;
81
+ }
82
+
83
+ export declare function createRenderRuntime(
84
+ hostAdapter: HostAdapter,
85
+ renderer: SimpRuntimeFCRenderer
86
+ ): SimpRenderRuntime;
87
+
88
+ export type LifecycleEvent =
89
+ | { type: 'beforeRender'; element: SimpElement; renderRuntime: SimpRenderRuntime }
90
+ | { type: 'afterRender'; element: SimpElement; renderRuntime: SimpRenderRuntime }
91
+ | { type: 'mounted'; element: SimpElement; renderRuntime: SimpRenderRuntime }
92
+ | { type: 'updated'; element: SimpElement; renderRuntime: SimpRenderRuntime }
93
+ | { type: 'unmounted'; element: SimpElement; renderRuntime: SimpRenderRuntime }
94
+ | { type: 'errored'; element: SimpElement; error: any; handled: boolean; renderRuntime: SimpRenderRuntime };
95
+
96
+ export interface LifecycleEventBus {
97
+ publish(event: LifecycleEvent): void;
98
+ subscribe(subscriber: (event: LifecycleEvent) => boolean | void): () => void;
99
+ }
100
+
101
+ export declare function isFC(element: { flag: number }): boolean;
102
+ export declare function isFragment(element: { flag: number }): boolean;
103
+ export declare function isHost(element: { flag: number }): boolean;
104
+ export declare function isPortal(element: { flag: number }): boolean;
105
+ export declare function isText(element: { flag: number }): boolean;
106
+ export declare function hasListChildren(element: { childFlag: number }): boolean;
107
+ export declare function hasElementChild(element: { childFlag: number }): boolean;
108
+
109
+ export declare function createElement(type: string | FC, props?: any, ...children: SimpNode[]): SimpElement;
110
+ export declare function Fragment(props: { children?: SimpNode }): SimpElement;
111
+
112
+ export declare function registerLifecyclePlugin(plugin: (bus: LifecycleEventBus) => void): void;
113
+
114
+ export declare function mount(
115
+ element: SimpElement,
116
+ parentReference: unknown,
117
+ subtreeRightBoundary: Nullable<SimpElement>,
118
+ context: unknown,
119
+ hostNamespace: Maybe<string>,
120
+ renderRuntime: SimpRenderRuntime
121
+ ): void;
122
+
123
+ export declare function patch(
124
+ prevElement: SimpElement,
125
+ nextElement: SimpElement,
126
+ parentReference: unknown,
127
+ subtreeRightBoundary: Nullable<SimpElement>,
128
+ context: unknown,
129
+ hostNamespace: Maybe<string>,
130
+ renderRuntime: SimpRenderRuntime
131
+ ): void;
132
+
133
+ export declare function unmount(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
134
+
135
+ export declare function rerender(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
136
+ export declare function withSyncRerender(renderRuntime: SimpRenderRuntime, callback: () => void): void;
package/core/internal.js CHANGED
@@ -1,16 +1,8 @@
1
- export * from './createElement.js';
2
- export * from './fragment.js';
3
- export * from './hostAdapter.js';
4
- export * from './lifecycleEventBus.js';
5
- export * from './memo.js';
6
- export * from './mounting.js';
7
- export * from './mountingChildren.js';
8
- export * from './patching.js';
9
- export * from './patchingChildren.js';
10
- export * from './portal.js';
11
- export * from './processStack.js';
12
- export * from './ref.js';
13
- export * from './rerender.js';
14
- export * from './runtime.js';
15
- export * from './unmounting.js';
16
- export * from './unmountingChildren.js';
1
+ export { createElement, hasElementChild, hasListChildren, isFC, isFragment, isHost, isPortal, isText, } from './createElement.js';
2
+ export { Fragment } from './fragment.js';
3
+ export { registerLifecyclePlugin } from './lifecycleEventBus.js';
4
+ export { mount } from './mounting.js';
5
+ export { patch } from './patching.js';
6
+ export { rerender, withSyncRerender } from './rerender.js';
7
+ export { createRenderRuntime } from './runtime.js';
8
+ export { unmount } from './unmounting.js';
@@ -1,16 +1,35 @@
1
- const subscribers = [];
2
- export const lifecycleEventBus = {
3
- publish(event) {
4
- for (const subscriber of subscribers) {
5
- subscriber(event);
6
- }
7
- },
8
- subscribe(subscriber) {
9
- if (subscribers.indexOf(subscriber) === -1) {
10
- subscribers.push(subscriber);
11
- }
12
- return () => {
13
- subscribers.splice(subscribers.indexOf(subscriber), 1);
14
- };
15
- },
16
- };
1
+ function createBus() {
2
+ const subscribers = [];
3
+ return {
4
+ publish(event) {
5
+ for (const subscriber of subscribers) {
6
+ subscriber(event);
7
+ }
8
+ },
9
+ subscribe(subscriber) {
10
+ if (subscribers.indexOf(subscriber) === -1) {
11
+ subscribers.push(subscriber);
12
+ }
13
+ return () => {
14
+ const index = subscribers.indexOf(subscriber);
15
+ if (index !== -1)
16
+ subscribers.splice(index, 1);
17
+ };
18
+ },
19
+ };
20
+ }
21
+ const busByRuntime = new WeakMap();
22
+ const plugins = [];
23
+ export function getLifecycleEventBus(runtime) {
24
+ let bus = busByRuntime.get(runtime);
25
+ if (!bus) {
26
+ bus = createBus();
27
+ for (const plugin of plugins)
28
+ plugin(bus);
29
+ busByRuntime.set(runtime, bus);
30
+ }
31
+ return bus;
32
+ }
33
+ export function registerLifecyclePlugin(plugin) {
34
+ plugins.push(plugin);
35
+ }
package/core/memo.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import { shallowEqual } from '../shared/index.js';
2
+ const MEMO_BRAND = Symbol('memo');
2
3
  export function memo(Component, compare = shallowEqual) {
3
4
  const Memoized = (props => Component(props));
4
5
  Memoized._compare = compare;
6
+ Memoized[MEMO_BRAND] = true;
7
+ Object.defineProperty(Memoized, 'name', { value: Component.name });
5
8
  return Memoized;
6
9
  }
7
10
  export function isMemo(type) {
8
- return !!type._compare;
11
+ return type?.[MEMO_BRAND] === true;
9
12
  }
package/core/mounting.js CHANGED
@@ -1,134 +1,92 @@
1
+ import { noop } from '../shared/index.js';
1
2
  import { createTextElement, normalizeRoot, SIMP_ELEMENT_CHILD_FLAG_TEXT, } from './createElement.js';
2
- import { _pushHostOperationPlaceElement } from './hostOperations.js';
3
- import { lifecycleEventBus } from './lifecycleEventBus.js';
4
- import { _pushMountChildrenFrame } from './mountingChildren.js';
5
- import { MOUNT_ENTER, MOUNT_EXIT, processStack } from './processStack.js';
3
+ import { pushHostOperationPlaceElement } from './hostOperations.js';
4
+ import { getLifecycleEventBus } from './lifecycleEventBus.js';
5
+ import { pushMountChildrenFrame } from './mountingChildren.js';
6
+ import { acquireMountFrame, MOUNT_ENTER, MOUNT_EXIT, processStack } from './processStack.js';
6
7
  import { applyRef } from './ref.js';
7
- import { MOUNTING_PHASE } from './runtime.js';
8
8
  import { bitScanForwardIndex } from './utils.js';
9
- const mountHandlers = [_mountHostElement, _mountFunctionalElement, _mountTextElement, _mountPortal, _mountFragment];
9
+ const mountEnterHandlers = [mountHostEnter, mountFCEnter, mountTextElement, mountPortalEnter, mountFragment];
10
+ const mountExitHandlers = [mountHostExit, mountFCExit, noop, mountPortalExit, noop];
10
11
  export function mount(element, parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime) {
11
12
  if (renderRuntime.renderStack.length !== 0) {
12
13
  throw new Error('Cannot mount while rendering.');
13
14
  }
14
- _pushMountEnterFrame(element, {
15
- parentReference,
16
- subtreeRightBoundary,
17
- context,
18
- hostNamespace,
19
- renderRuntime,
20
- placeHolderElement: null,
21
- });
15
+ pushMountEnterFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, null);
22
16
  processStack(renderRuntime);
23
17
  }
24
- export function _mount(frame) {
25
- mountHandlers[bitScanForwardIndex(frame.node.flag)](frame);
18
+ export function mountEnter(frame) {
19
+ mountEnterHandlers[bitScanForwardIndex(frame.node.flag)](frame);
26
20
  }
27
- export function _pushMountEnterFrame(element, meta) {
28
- meta.renderRuntime.renderStack.push({
29
- node: element,
30
- kind: MOUNT_ENTER,
31
- meta,
32
- });
21
+ export function mountExit(frame) {
22
+ mountExitHandlers[bitScanForwardIndex(frame.node.flag)](frame);
33
23
  }
34
- function _pushMountExitFrame(element, meta) {
35
- meta.renderRuntime.renderStack.push({
36
- node: element,
37
- kind: MOUNT_EXIT,
38
- meta,
39
- });
24
+ export function pushMountEnterFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement) {
25
+ renderRuntime.renderStack.push(acquireMountFrame(renderRuntime, element, MOUNT_ENTER, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement));
26
+ }
27
+ function pushMountExitFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement) {
28
+ renderRuntime.renderStack.push(acquireMountFrame(renderRuntime, element, MOUNT_EXIT, parentReference, subtreeRightBoundary, context, hostNamespace, placeHolderElement));
40
29
  }
41
- function _mountHostElement(frame) {
30
+ function mountHostEnter(frame) {
42
31
  const element = frame.node;
43
- const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame.meta;
44
- if (frame.kind === MOUNT_EXIT) {
45
- if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_TEXT) {
46
- renderRuntime.hostAdapter.setTextContent(element.reference, element.props.children);
47
- }
48
- if (element.props) {
49
- renderRuntime.hostAdapter.mountProps(element.reference, element, renderRuntime, hostNamespace);
50
- }
51
- if (element.className) {
52
- renderRuntime.hostAdapter.setClassname(element.reference, element.className, hostNamespace);
53
- }
54
- if (parentReference) {
55
- _pushHostOperationPlaceElement(element, {
56
- renderRuntime,
57
- subtreeRightBoundary,
58
- parentReference,
59
- });
60
- }
61
- applyRef(element);
62
- return;
63
- }
32
+ const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame;
64
33
  const hostNamespaces = renderRuntime.hostAdapter.getHostNamespaces(element, hostNamespace);
65
34
  const hostReference = (element.reference = renderRuntime.hostAdapter.createReference(element.type, hostNamespaces?.self));
66
35
  renderRuntime.hostAdapter.attachElementToReference(element, hostReference, renderRuntime);
67
- _pushMountExitFrame(element, {
68
- renderRuntime,
69
- hostNamespace: hostNamespaces?.self,
70
- subtreeRightBoundary,
71
- context,
72
- parentReference,
73
- placeHolderElement: null,
74
- });
75
- _pushMountChildrenFrame(element, {
76
- renderRuntime,
77
- hostNamespace: hostNamespaces?.children,
78
- subtreeRightBoundary,
79
- context,
80
- parentReference: hostReference,
81
- children: element.children,
82
- });
36
+ pushMountExitFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespaces?.self, null);
37
+ pushMountChildrenFrame(element, renderRuntime, element.children, hostReference, subtreeRightBoundary, context, hostNamespaces?.children);
83
38
  }
84
- function _mountFunctionalElement(frame) {
39
+ function mountHostExit(frame) {
85
40
  const element = frame.node;
86
- const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame.meta;
87
- if (frame.kind === MOUNT_EXIT) {
88
- lifecycleEventBus.publish({ type: 'mounted', element, renderRuntime });
89
- return;
41
+ const { parentReference, subtreeRightBoundary, hostNamespace, renderRuntime } = frame;
42
+ if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_TEXT) {
43
+ renderRuntime.hostAdapter.setTextContent(element.reference, element.props.children);
90
44
  }
45
+ if (element.props) {
46
+ renderRuntime.hostAdapter.mountProps(element.reference, element, renderRuntime, hostNamespace);
47
+ }
48
+ if (element.className) {
49
+ renderRuntime.hostAdapter.setClassname(element.reference, element.className, hostNamespace);
50
+ }
51
+ if (parentReference) {
52
+ pushHostOperationPlaceElement(element, renderRuntime, parentReference, subtreeRightBoundary);
53
+ }
54
+ applyRef(element);
55
+ }
56
+ function mountFCEnter(frame) {
57
+ const element = frame.node;
58
+ const { parentReference, subtreeRightBoundary, context, hostNamespace, renderRuntime } = frame;
91
59
  if (context) {
92
60
  element.context = context;
93
61
  }
94
62
  if (element.unmounted) {
95
63
  element.unmounted = false;
96
64
  }
97
- element.store = { latestElement: null, hostNamespace: null, forceRerender: false };
98
- element.store.latestElement = element;
99
65
  if (hostNamespace) {
100
- element.store.hostNamespace = hostNamespace;
66
+ element.hostNamespace = hostNamespace;
101
67
  }
102
- // FC element always has Maybe<SimpElement> children due to a normalization process.
103
68
  let children;
104
- let triedToRerenderUnsubscribe;
105
69
  try {
106
- renderRuntime.renderPhase = MOUNTING_PHASE;
107
- renderRuntime.currentRenderingFCElement = element;
108
- let triedToRerender = false;
109
70
  let rerenderCounter = 0;
110
- triedToRerenderUnsubscribe = lifecycleEventBus.subscribe(event => {
111
- if (event.type === 'triedToRerender' && event.element === element) {
112
- triedToRerender = true;
113
- }
114
- });
71
+ renderRuntime.activeRenderElement = element;
72
+ renderRuntime.pendingRerenderFlag = false;
115
73
  do {
116
- triedToRerender = false;
74
+ renderRuntime.pendingRerenderFlag = false;
117
75
  if (++rerenderCounter >= 25) {
118
76
  throw new Error('Too many re-renders.');
119
77
  }
120
- lifecycleEventBus.publish({
78
+ getLifecycleEventBus(renderRuntime).publish({
121
79
  type: 'beforeRender',
122
80
  element,
123
81
  renderRuntime,
124
82
  });
125
83
  children = renderRuntime.renderer(element.type, element, renderRuntime);
126
- lifecycleEventBus.publish({
84
+ getLifecycleEventBus(renderRuntime).publish({
127
85
  type: 'afterRender',
128
86
  element,
129
87
  renderRuntime,
130
88
  });
131
- } while (triedToRerender);
89
+ } while (renderRuntime.pendingRerenderFlag);
132
90
  normalizeRoot(element, children, false);
133
91
  children = element.children;
134
92
  }
@@ -140,80 +98,42 @@ function _mountFunctionalElement(frame) {
140
98
  handled: false,
141
99
  renderRuntime,
142
100
  };
143
- lifecycleEventBus.publish(event);
101
+ getLifecycleEventBus(renderRuntime).publish(event);
144
102
  if (!event.handled) {
145
103
  throw new Error('Error occurred during rendering a component', { cause: event.error });
146
104
  }
147
105
  return;
148
106
  }
149
107
  finally {
150
- triedToRerenderUnsubscribe();
151
- renderRuntime.renderPhase = null;
152
- renderRuntime.currentRenderingFCElement = null;
108
+ renderRuntime.activeRenderElement = null;
153
109
  }
154
- _pushMountExitFrame(element, {
155
- renderRuntime,
156
- hostNamespace,
157
- subtreeRightBoundary,
158
- context,
159
- parentReference,
160
- placeHolderElement: null,
161
- });
162
- _pushMountChildrenFrame(element, {
163
- renderRuntime,
164
- hostNamespace,
165
- children: children,
166
- context: element.context,
167
- parentReference,
168
- subtreeRightBoundary,
110
+ pushMountExitFrame(element, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, null);
111
+ pushMountChildrenFrame(element, renderRuntime, children, parentReference, subtreeRightBoundary, element.context, hostNamespace);
112
+ }
113
+ function mountFCExit(frame) {
114
+ getLifecycleEventBus(frame.renderRuntime).publish({
115
+ type: 'mounted',
116
+ element: frame.node,
117
+ renderRuntime: frame.renderRuntime,
169
118
  });
170
119
  }
171
- function _mountTextElement(frame) {
172
- frame.node.reference = frame.meta.renderRuntime.hostAdapter.createTextReference(frame.node.children);
173
- _pushHostOperationPlaceElement(frame.node, frame.meta);
120
+ function mountTextElement(frame) {
121
+ frame.node.reference = frame.renderRuntime.hostAdapter.createTextReference(frame.node.children);
122
+ pushHostOperationPlaceElement(frame.node, frame.renderRuntime, frame.parentReference, frame.subtreeRightBoundary);
174
123
  }
175
- function _mountPortal(frame) {
124
+ function mountPortalEnter(frame) {
176
125
  const element = frame.node;
177
- const { parentReference, subtreeRightBoundary, context, renderRuntime } = frame.meta;
178
- if (frame.kind === MOUNT_EXIT) {
179
- element.reference = frame.meta.placeHolderElement.reference;
180
- return;
181
- }
126
+ const { parentReference, subtreeRightBoundary, context, renderRuntime } = frame;
182
127
  const placeHolderElement = createTextElement('');
183
- _pushMountExitFrame(element, {
184
- renderRuntime,
185
- subtreeRightBoundary,
186
- context: null,
187
- parentReference: null,
188
- hostNamespace: null,
189
- placeHolderElement,
190
- });
191
- _pushMountChildrenFrame(element, {
192
- renderRuntime,
193
- hostNamespace: renderRuntime.hostAdapter.getHostNamespaces(element.children, undefined)?.self,
194
- subtreeRightBoundary,
195
- context,
196
- parentReference: element.ref,
197
- children: element.children,
198
- });
199
- _pushMountEnterFrame(placeHolderElement, {
200
- renderRuntime,
201
- subtreeRightBoundary,
202
- context: null,
203
- parentReference,
204
- hostNamespace: null,
205
- placeHolderElement: null,
206
- });
128
+ pushMountExitFrame(element, renderRuntime, null, subtreeRightBoundary, null, null, placeHolderElement);
129
+ pushMountChildrenFrame(element, renderRuntime, element.children, element.ref, subtreeRightBoundary, context, renderRuntime.hostAdapter.getHostNamespaces(element.children, undefined)?.self);
130
+ pushMountEnterFrame(placeHolderElement, renderRuntime, parentReference, subtreeRightBoundary, null, null, null);
131
+ }
132
+ function mountPortalExit(frame) {
133
+ frame.node.reference = frame.placeHolderElement.reference;
207
134
  }
208
- function _mountFragment(frame) {
135
+ function mountFragment(frame) {
209
136
  const element = frame.node;
210
- const { parentReference, hostNamespace, context, renderRuntime, subtreeRightBoundary } = frame.meta;
211
- _pushMountChildrenFrame(element, {
212
- renderRuntime,
213
- hostNamespace,
214
- children: element.children,
215
- parentReference,
216
- context,
217
- subtreeRightBoundary: subtreeRightBoundary,
218
- });
137
+ const { parentReference, hostNamespace, context, renderRuntime, subtreeRightBoundary } = frame;
138
+ pushMountChildrenFrame(element, renderRuntime, element.children, parentReference, subtreeRightBoundary, context, hostNamespace);
219
139
  }
@@ -1,46 +1,28 @@
1
1
  import { SIMP_ELEMENT_CHILD_FLAG_ELEMENT, SIMP_ELEMENT_CHILD_FLAG_LIST } from './createElement.js';
2
- import { _pushMountEnterFrame } from './mounting.js';
3
- import { MOUNT_CHILDREN_ENTER } from './processStack.js';
2
+ import { pushMountEnterFrame } from './mounting.js';
3
+ import { acquireMountChildrenFrame } from './processStack.js';
4
4
  import { isHostLike } from './utils.js';
5
- export function _pushMountChildrenFrame(parent, meta) {
6
- meta.renderRuntime.renderStack.push({
7
- node: parent,
8
- kind: MOUNT_CHILDREN_ENTER,
9
- meta,
10
- });
5
+ export function pushMountChildrenFrame(parent, renderRuntime, children, parentReference, subtreeRightBoundary, context, hostNamespace) {
6
+ renderRuntime.renderStack.push(acquireMountChildrenFrame(renderRuntime, parent, children, parentReference, subtreeRightBoundary, context, hostNamespace));
11
7
  }
12
- export function _mountChildren(frame) {
8
+ export function mountChildren(frame) {
13
9
  const parentElement = frame.node;
14
- const { parentReference, hostNamespace, renderRuntime, context } = frame.meta;
15
- const subtreeRightBoundary = isHostLike(parentElement.flag) ? null : frame.meta.subtreeRightBoundary;
10
+ const { parentReference, hostNamespace, renderRuntime, context } = frame;
11
+ const subtreeRightBoundary = isHostLike(parentElement.flag) ? null : frame.subtreeRightBoundary;
16
12
  switch (parentElement.childFlag) {
17
13
  case SIMP_ELEMENT_CHILD_FLAG_ELEMENT: {
18
- const children = frame.meta.children;
14
+ const children = frame.children;
19
15
  children.parent = parentElement;
20
- _pushMountEnterFrame(children, {
21
- renderRuntime,
22
- hostNamespace,
23
- subtreeRightBoundary,
24
- context,
25
- parentReference,
26
- placeHolderElement: null,
27
- });
16
+ pushMountEnterFrame(children, renderRuntime, parentReference, subtreeRightBoundary, context, hostNamespace, null);
28
17
  break;
29
18
  }
30
19
  case SIMP_ELEMENT_CHILD_FLAG_LIST: {
31
- const children = frame.meta.children;
20
+ const children = frame.children;
32
21
  for (let i = children.length - 1; i >= 0; i--) {
33
22
  const child = children[i];
34
23
  child.parent = parentElement;
35
24
  const rightSibling = children[child.index + 1] || subtreeRightBoundary;
36
- _pushMountEnterFrame(child, {
37
- renderRuntime,
38
- parentReference,
39
- context,
40
- hostNamespace,
41
- subtreeRightBoundary: rightSibling,
42
- placeHolderElement: null,
43
- });
25
+ pushMountEnterFrame(child, renderRuntime, parentReference, rightSibling, context, hostNamespace, null);
44
26
  }
45
27
  }
46
28
  }