@lynx-js/react 0.111.0 → 0.111.2

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 (144) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/components/lib/DeferredListItem.d.ts +3 -1
  3. package/components/lib/DeferredListItem.jsx +4 -2
  4. package/components/lib/DeferredListItem.jsx.map +1 -1
  5. package/components/src/DeferredListItem.tsx +5 -3
  6. package/package.json +6 -1
  7. package/refresh/.turbo/turbo-build.log +7 -3
  8. package/refresh/dist/index.js +223 -284
  9. package/refresh/package.json +3 -4
  10. package/refresh/rslib.config.ts +24 -0
  11. package/runtime/debug/index.cjs +8 -0
  12. package/runtime/debug/index.d.ts +4 -0
  13. package/runtime/debug/index.js +5 -0
  14. package/runtime/lib/alog/index.d.ts +1 -0
  15. package/runtime/lib/alog/index.js +8 -0
  16. package/runtime/lib/alog/index.js.map +1 -0
  17. package/runtime/lib/alog/render.d.ts +1 -0
  18. package/runtime/lib/alog/render.js +19 -0
  19. package/runtime/lib/alog/render.js.map +1 -0
  20. package/runtime/lib/backgroundSnapshot.d.ts +1 -0
  21. package/runtime/lib/backgroundSnapshot.js +31 -17
  22. package/runtime/lib/backgroundSnapshot.js.map +1 -1
  23. package/runtime/lib/debug/component-stack.d.ts +33 -0
  24. package/runtime/lib/debug/component-stack.js +145 -0
  25. package/runtime/lib/debug/component-stack.js.map +1 -0
  26. package/runtime/lib/debug/formatPatch.d.ts +2 -0
  27. package/runtime/lib/debug/formatPatch.js +27 -0
  28. package/runtime/lib/debug/formatPatch.js.map +1 -0
  29. package/runtime/lib/debug/printSnapshot.d.ts +1 -1
  30. package/runtime/lib/debug/printSnapshot.js +0 -4
  31. package/runtime/lib/debug/printSnapshot.js.map +1 -1
  32. package/runtime/lib/debug/profile.js +1 -3
  33. package/runtime/lib/debug/profile.js.map +1 -1
  34. package/runtime/lib/hydrate.js +11 -7
  35. package/runtime/lib/hydrate.js.map +1 -1
  36. package/runtime/lib/lifecycle/patch/commit.js +1 -1
  37. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  38. package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +4 -0
  39. package/runtime/lib/lifecycle/patch/snapshotPatch.js +28 -0
  40. package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
  41. package/runtime/lib/lynx.js +9 -0
  42. package/runtime/lib/lynx.js.map +1 -1
  43. package/runtime/lib/pendingListUpdates.d.ts +2 -1
  44. package/runtime/lib/pendingListUpdates.js +16 -4
  45. package/runtime/lib/pendingListUpdates.js.map +1 -1
  46. package/runtime/lib/renderToOpcodes/constants.d.ts +2 -0
  47. package/runtime/lib/renderToOpcodes/constants.js +2 -0
  48. package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
  49. package/runtime/lib/root.d.ts +6 -0
  50. package/runtime/lib/root.js +4 -0
  51. package/runtime/lib/root.js.map +1 -1
  52. package/runtime/lib/snapshot/platformInfo.js +5 -3
  53. package/runtime/lib/snapshot/platformInfo.js.map +1 -1
  54. package/runtime/lib/snapshot/ref.d.ts +2 -2
  55. package/runtime/lib/snapshot/spread.js +3 -1
  56. package/runtime/lib/snapshot/spread.js.map +1 -1
  57. package/runtime/lib/snapshot.js +13 -7
  58. package/runtime/lib/snapshot.js.map +1 -1
  59. package/runtime/lib/utils.d.ts +2 -0
  60. package/runtime/lib/utils.js +23 -2
  61. package/runtime/lib/utils.js.map +1 -1
  62. package/testing-library/dist/env/vitest.js +18 -7
  63. package/testing-library/dist/pure.js +3 -1
  64. package/testing-library/dist/vitest-global-setup.js +2 -2
  65. package/transform/dist/wasm.cjs +1 -1
  66. package/types/react.d.ts +13 -1
  67. package/worklet-runtime/dist/dev.js +403 -506
  68. package/worklet-runtime/dist/main.js +1 -517
  69. package/worklet-runtime/lib/workletRuntime.js +5 -5
  70. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
  71. package/runtime/src/backgroundSnapshot.ts +0 -501
  72. package/runtime/src/compat/componentIs.ts +0 -30
  73. package/runtime/src/compat/initData.ts +0 -150
  74. package/runtime/src/compat/lynxComponent.ts +0 -79
  75. package/runtime/src/debug/debug.ts +0 -9
  76. package/runtime/src/debug/printSnapshot.ts +0 -28
  77. package/runtime/src/debug/profile.ts +0 -55
  78. package/runtime/src/document.ts +0 -84
  79. package/runtime/src/gesture/processGesture.ts +0 -89
  80. package/runtime/src/gesture/processGestureBagkround.ts +0 -19
  81. package/runtime/src/gesture/types.ts +0 -44
  82. package/runtime/src/hooks/react.ts +0 -62
  83. package/runtime/src/hooks/useLynxGlobalEventListener.ts +0 -59
  84. package/runtime/src/hydrate.ts +0 -368
  85. package/runtime/src/index.ts +0 -94
  86. package/runtime/src/internal.ts +0 -63
  87. package/runtime/src/legacy-react-runtime/index.ts +0 -42
  88. package/runtime/src/lifecycle/destroy.ts +0 -34
  89. package/runtime/src/lifecycle/event/delayEvents.ts +0 -11
  90. package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +0 -15
  91. package/runtime/src/lifecycle/event/jsReady.ts +0 -34
  92. package/runtime/src/lifecycle/pass.ts +0 -14
  93. package/runtime/src/lifecycle/patch/commit.ts +0 -214
  94. package/runtime/src/lifecycle/patch/error.ts +0 -61
  95. package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +0 -13
  96. package/runtime/src/lifecycle/patch/snapshotPatch.ts +0 -65
  97. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +0 -145
  98. package/runtime/src/lifecycle/patch/updateMainThread.ts +0 -64
  99. package/runtime/src/lifecycle/ref/delay.ts +0 -99
  100. package/runtime/src/lifecycle/reload.ts +0 -97
  101. package/runtime/src/lifecycle/render.ts +0 -54
  102. package/runtime/src/lifecycleConstant.ts +0 -21
  103. package/runtime/src/list.ts +0 -307
  104. package/runtime/src/listUpdateInfo.ts +0 -221
  105. package/runtime/src/lynx/calledByNative.ts +0 -160
  106. package/runtime/src/lynx/component.ts +0 -113
  107. package/runtime/src/lynx/dynamic-js.ts +0 -36
  108. package/runtime/src/lynx/env.ts +0 -109
  109. package/runtime/src/lynx/injectLepusMethods.ts +0 -53
  110. package/runtime/src/lynx/lazy-bundle.ts +0 -175
  111. package/runtime/src/lynx/performance.ts +0 -148
  112. package/runtime/src/lynx/runWithForce.ts +0 -67
  113. package/runtime/src/lynx/tt.ts +0 -215
  114. package/runtime/src/lynx-api.ts +0 -455
  115. package/runtime/src/lynx.ts +0 -58
  116. package/runtime/src/opcodes.ts +0 -155
  117. package/runtime/src/pendingListUpdates.ts +0 -18
  118. package/runtime/src/renderToOpcodes/constants.ts +0 -24
  119. package/runtime/src/renderToOpcodes/index.ts +0 -306
  120. package/runtime/src/root.ts +0 -23
  121. package/runtime/src/snapshot/dynamicPartType.ts +0 -16
  122. package/runtime/src/snapshot/event.ts +0 -33
  123. package/runtime/src/snapshot/gesture.ts +0 -30
  124. package/runtime/src/snapshot/list.ts +0 -36
  125. package/runtime/src/snapshot/platformInfo.ts +0 -62
  126. package/runtime/src/snapshot/ref.ts +0 -139
  127. package/runtime/src/snapshot/spread.ts +0 -330
  128. package/runtime/src/snapshot/workletEvent.ts +0 -35
  129. package/runtime/src/snapshot/workletRef.ts +0 -88
  130. package/runtime/src/snapshot.ts +0 -634
  131. package/runtime/src/snapshotInstanceHydrationMap.ts +0 -17
  132. package/runtime/src/utils.ts +0 -44
  133. package/runtime/src/worklet/ctx.ts +0 -22
  134. package/runtime/src/worklet/destroy.ts +0 -16
  135. package/runtime/src/worklet/execMap.ts +0 -51
  136. package/runtime/src/worklet/functionCall.ts +0 -42
  137. package/runtime/src/worklet/functionality.ts +0 -29
  138. package/runtime/src/worklet/hmr.ts +0 -34
  139. package/runtime/src/worklet/indexMap.ts +0 -23
  140. package/runtime/src/worklet/runOnBackground.ts +0 -147
  141. package/runtime/src/worklet/runOnMainThread.ts +0 -50
  142. package/runtime/src/worklet/transformToWorklet.ts +0 -26
  143. package/runtime/src/worklet/workletRef.ts +0 -231
  144. package/runtime/src/worklet/workletRefPool.ts +0 -29
@@ -1,148 +0,0 @@
1
- // Copyright 2024 The Lynx Authors. All rights reserved.
2
- // Licensed under the Apache License Version 2.0 that can be found in the
3
- // LICENSE file in the root directory of this source tree.
4
- import { options } from 'preact';
5
- import type { VNode } from 'preact';
6
-
7
- import { __globalSnapshotPatch } from '../lifecycle/patch/snapshotPatch.js';
8
- import { DIFF } from '../renderToOpcodes/constants.js';
9
- import { isSdkVersionGt } from '../utils.js';
10
-
11
- const PerformanceTimingKeys = [
12
- 'updateSetStateTrigger',
13
- 'updateDiffVdomStart',
14
- 'updateDiffVdomEnd',
15
- // updateSetStateTrigger, updateDiffVdomStart and updateDiffVdomEnd is deprecated
16
- 'diffVdomStart',
17
- 'diffVdomEnd',
18
- 'packChangesStart',
19
- 'packChangesEnd',
20
- 'parseChangesStart',
21
- 'parseChangesEnd',
22
- 'patchChangesStart',
23
- 'patchChangesEnd',
24
- 'hydrateParseSnapshotStart',
25
- 'hydrateParseSnapshotEnd',
26
- 'mtsRenderStart',
27
- 'mtsRenderEnd',
28
- ] as const;
29
-
30
- const PerformanceTimingFlags = {
31
- reactLynxHydrate: 'react_lynx_hydrate',
32
- } as const;
33
-
34
- const PipelineOrigins = {
35
- reactLynxHydrate: 'reactLynxHydrate',
36
- updateTriggeredByBts: 'updateTriggeredByBts',
37
- } as const;
38
-
39
- type PipelineOrigin = typeof PipelineOrigins[keyof typeof PipelineOrigins];
40
-
41
- /**
42
- * @deprecated used by old timing api(setState timing flag)
43
- */
44
- const PerfSpecificKey = '__lynx_timing_flag';
45
- let timingFlag: string | undefined;
46
- let shouldMarkDiffVdomStart = false;
47
- let shouldMarkDiffVdomEnd = false;
48
-
49
- let globalPipelineOptions: PipelineOptions | undefined;
50
-
51
- /**
52
- * @deprecated used by old timing api(setState timing flag)
53
- */
54
- function markTimingLegacy(key: typeof PerformanceTimingKeys[number], timingFlag_?: string): void {
55
- switch (key) {
56
- case 'updateSetStateTrigger': {
57
- shouldMarkDiffVdomStart = true;
58
- shouldMarkDiffVdomEnd = true;
59
- timingFlag = timingFlag_;
60
- break;
61
- }
62
- case 'updateDiffVdomStart': {
63
- /* v8 ignore start */
64
- if (!shouldMarkDiffVdomStart) {
65
- return;
66
- }
67
- /* v8 ignore stop */
68
- shouldMarkDiffVdomStart = false;
69
- break;
70
- }
71
- case 'updateDiffVdomEnd': {
72
- if (!shouldMarkDiffVdomEnd) {
73
- return;
74
- }
75
- shouldMarkDiffVdomEnd = false;
76
- break;
77
- }
78
- }
79
- lynx.getNativeApp().markTiming?.(timingFlag!, key);
80
- }
81
-
82
- function beginPipeline(needTimestamps: boolean, pipelineOrigin: PipelineOrigin, timingFlag?: string): void {
83
- globalPipelineOptions = lynx.performance?._generatePipelineOptions?.();
84
- if (globalPipelineOptions) {
85
- globalPipelineOptions.needTimestamps = needTimestamps;
86
- globalPipelineOptions.pipelineOrigin = pipelineOrigin;
87
- globalPipelineOptions.dsl = 'reactLynx';
88
- switch (pipelineOrigin) {
89
- case PipelineOrigins.reactLynxHydrate:
90
- globalPipelineOptions.stage = 'hydrate';
91
- break;
92
- case PipelineOrigins.updateTriggeredByBts:
93
- globalPipelineOptions.stage = 'update';
94
- break;
95
- }
96
-
97
- if (isSdkVersionGt(3, 0)) {
98
- lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID, globalPipelineOptions);
99
- } else {
100
- lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID);
101
- }
102
- if (timingFlag) {
103
- lynx.performance?._bindPipelineIdWithTimingFlag?.(globalPipelineOptions.pipelineID, timingFlag);
104
- }
105
- }
106
- }
107
-
108
- function setPipeline(pipeline: PipelineOptions | undefined): void {
109
- globalPipelineOptions = pipeline;
110
- }
111
-
112
- function markTiming(timestampKey: typeof PerformanceTimingKeys[number], force?: boolean): void {
113
- if (globalPipelineOptions && (force || globalPipelineOptions.needTimestamps)) {
114
- lynx.performance?._markTiming?.(globalPipelineOptions.pipelineID, timestampKey);
115
- }
116
- }
117
-
118
- function initTimingAPI(): void {
119
- const oldDiff = options[DIFF];
120
- options[DIFF] = (vnode: VNode) => {
121
- // check `__globalSnapshotPatch` to make sure this only runs after hydrate
122
- if (__JS__ && __globalSnapshotPatch) {
123
- if (!globalPipelineOptions) {
124
- beginPipeline(false, PipelineOrigins.updateTriggeredByBts);
125
- markTiming('diffVdomStart', true);
126
- }
127
- if (shouldMarkDiffVdomStart) {
128
- markTimingLegacy('updateDiffVdomStart');
129
- }
130
- }
131
- oldDiff?.(vnode);
132
- };
133
- }
134
-
135
- /**
136
- * @internal
137
- */
138
- export {
139
- PerformanceTimingFlags,
140
- PipelineOrigins,
141
- PerfSpecificKey,
142
- markTimingLegacy,
143
- initTimingAPI,
144
- beginPipeline,
145
- markTiming,
146
- setPipeline,
147
- globalPipelineOptions,
148
- };
@@ -1,67 +0,0 @@
1
- // Copyright 2025 The Lynx Authors. All rights reserved.
2
- // Licensed under the Apache License Version 2.0 that can be found in the
3
- // LICENSE file in the root directory of this source tree.
4
- import { options } from 'preact';
5
- import type { Component, VNode } from 'preact';
6
-
7
- import { COMPONENT, DIFF, DIFFED, FORCE } from '../renderToOpcodes/constants.js';
8
-
9
- const sForcedVNode = Symbol('FORCE');
10
-
11
- type PatchedVNode = VNode & { [sForcedVNode]?: true };
12
-
13
- export function runWithForce(cb: () => void): void {
14
- // save vnode and its `_component` in WeakMap
15
- const m = new WeakMap<VNode, Component>();
16
-
17
- const oldDiff = options[DIFF];
18
-
19
- options[DIFF] = (vnode: PatchedVNode) => {
20
- if (oldDiff) {
21
- oldDiff(vnode);
22
- }
23
-
24
- // when `options[DIFF]` is called, a newVnode is passed in
25
- // so its `vnode[COMPONENT]` should be null,
26
- // but it will be set later
27
- Object.defineProperty(vnode, COMPONENT, {
28
- configurable: true,
29
- set(c: Component) {
30
- m.set(vnode, c);
31
- if (c) {
32
- c[FORCE] = true;
33
- }
34
- },
35
- get(): Component | undefined {
36
- return m.get(vnode);
37
- },
38
- });
39
- vnode[sForcedVNode] = true;
40
- };
41
-
42
- const oldDiffed = options[DIFFED];
43
-
44
- options[DIFFED] = (vnode: PatchedVNode) => {
45
- if (oldDiffed) {
46
- oldDiffed(vnode);
47
- }
48
-
49
- // There would be cases when `options[DIFF]` has been reset while options[DIFFED] is not,
50
- // so we need to check if `vnode` is patched by `options[DIFF]`.
51
- // We only want to change the patched vnode
52
- if (vnode[sForcedVNode]) {
53
- // delete is a reverse operation of previous `Object.defineProperty`
54
- delete vnode[COMPONENT];
55
- delete vnode[sForcedVNode];
56
- // restore
57
- vnode[COMPONENT] = m.get(vnode)!;
58
- }
59
- };
60
-
61
- try {
62
- cb();
63
- } finally {
64
- options[DIFF] = oldDiff as (vnode: VNode) => void;
65
- options[DIFFED] = oldDiffed as (vnode: VNode) => void;
66
- }
67
- }
@@ -1,215 +0,0 @@
1
- // Copyright 2024 The Lynx Authors. All rights reserved.
2
- // Licensed under the Apache License Version 2.0 that can be found in the
3
- // LICENSE file in the root directory of this source tree.
4
- import { render } from 'preact';
5
-
6
- import { LifecycleConstant, NativeUpdateDataType } from '../lifecycleConstant.js';
7
- import type { FirstScreenData } from '../lifecycleConstant.js';
8
- import { PerformanceTimingFlags, PipelineOrigins, beginPipeline, markTiming } from './performance.js';
9
- import { BackgroundSnapshotInstance, hydrate } from '../backgroundSnapshot.js';
10
- import { runWithForce } from './runWithForce.js';
11
- import { destroyBackground } from '../lifecycle/destroy.js';
12
- import { delayedEvents, delayedPublishEvent } from '../lifecycle/event/delayEvents.js';
13
- import { delayLifecycleEvent, delayedLifecycleEvents } from '../lifecycle/event/delayLifecycleEvents.js';
14
- import { commitPatchUpdate, genCommitTaskId, globalCommitTaskMap } from '../lifecycle/patch/commit.js';
15
- import type { PatchList } from '../lifecycle/patch/commit.js';
16
- import { removeCtxNotFoundEventListener } from '../lifecycle/patch/error.js';
17
- import { runDelayedUiOps } from '../lifecycle/ref/delay.js';
18
- import { reloadBackground } from '../lifecycle/reload.js';
19
- import { CHILDREN } from '../renderToOpcodes/constants.js';
20
- import { __root } from '../root.js';
21
- import { backgroundSnapshotInstanceManager } from '../snapshot.js';
22
- import type { SerializedSnapshotInstance } from '../snapshot.js';
23
- import { destroyWorklet } from '../worklet/destroy.js';
24
-
25
- export { runWithForce };
26
-
27
- function injectTt(): void {
28
- const tt = lynxCoreInject.tt;
29
- tt.OnLifecycleEvent = onLifecycleEvent;
30
- tt.publishEvent = delayedPublishEvent;
31
- tt.publicComponentEvent = delayedPublicComponentEvent;
32
- tt.callDestroyLifetimeFun = () => {
33
- destroyWorklet();
34
- destroyBackground();
35
- removeCtxNotFoundEventListener();
36
- };
37
- tt.updateGlobalProps = updateGlobalProps;
38
- tt.updateCardData = updateCardData;
39
- tt.onAppReload = reloadBackground;
40
- tt.processCardConfig = () => {
41
- // used to updateTheme, no longer rely on this function
42
- };
43
- }
44
-
45
- function onLifecycleEvent([type, data]: [LifecycleConstant, unknown]) {
46
- const hasRootRendered = CHILDREN in __root;
47
- // never called `render(<App/>, __root)`
48
- // happens if user call `root.render()` async
49
- if (!hasRootRendered) {
50
- delayLifecycleEvent(type, data);
51
- return;
52
- }
53
-
54
- if (__PROFILE__) {
55
- console.profile(`OnLifecycleEvent::${type}`);
56
- }
57
-
58
- try {
59
- onLifecycleEventImpl(type, data);
60
- } catch (e) {
61
- lynx.reportError(e as Error);
62
- }
63
-
64
- if (__PROFILE__) {
65
- console.profileEnd();
66
- }
67
- }
68
-
69
- function onLifecycleEventImpl(type: LifecycleConstant, data: unknown): void {
70
- switch (type) {
71
- case LifecycleConstant.firstScreen: {
72
- const { root: lepusSide, jsReadyEventIdSwap } = data as FirstScreenData;
73
- if (__PROFILE__) {
74
- console.profile('hydrate');
75
- }
76
- beginPipeline(true, PipelineOrigins.reactLynxHydrate, PerformanceTimingFlags.reactLynxHydrate);
77
- markTiming('hydrateParseSnapshotStart');
78
- const before = JSON.parse(lepusSide) as SerializedSnapshotInstance;
79
- markTiming('hydrateParseSnapshotEnd');
80
- markTiming('diffVdomStart');
81
- const snapshotPatch = hydrate(
82
- before,
83
- __root as BackgroundSnapshotInstance,
84
- );
85
- if (__PROFILE__) {
86
- console.profileEnd();
87
- }
88
- markTiming('diffVdomEnd');
89
-
90
- // TODO: It seems `delayedEvents` and `delayedLifecycleEvents` should be merged into one array to ensure the proper order of events.
91
- flushDelayedLifecycleEvents();
92
- if (delayedEvents) {
93
- delayedEvents.forEach((args) => {
94
- const [handlerName, data] = args;
95
- // eslint-disable-next-line prefer-const
96
- let [idStr, ...rest] = handlerName.split(':');
97
- while (jsReadyEventIdSwap[idStr!]) idStr = jsReadyEventIdSwap[idStr!]?.toString();
98
- try {
99
- publishEvent([idStr, ...rest].join(':'), data);
100
- } catch (e) {
101
- lynx.reportError(e as Error);
102
- }
103
- });
104
- delayedEvents.length = 0;
105
- }
106
-
107
- lynxCoreInject.tt.publishEvent = publishEvent;
108
- lynxCoreInject.tt.publicComponentEvent = publicComponentEvent;
109
-
110
- // console.debug("********** After hydration:");
111
- // printSnapshotInstance(__root as BackgroundSnapshotInstance);
112
- if (__PROFILE__) {
113
- console.profile('commitChanges');
114
- }
115
- const commitTaskId = genCommitTaskId();
116
- const patchList: PatchList = {
117
- patchList: [{ snapshotPatch, id: commitTaskId }],
118
- };
119
- const obj = commitPatchUpdate(patchList, { isHydration: true });
120
-
121
- lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, obj, () => {
122
- globalCommitTaskMap.forEach((commitTask, id) => {
123
- if (id > commitTaskId) {
124
- return;
125
- }
126
- commitTask();
127
- globalCommitTaskMap.delete(id);
128
- });
129
- });
130
- runDelayedUiOps();
131
- break;
132
- }
133
- case LifecycleConstant.globalEventFromLepus: {
134
- const [eventName, params] = data as [string, Record<string, any>];
135
- lynx.getJSModule('GlobalEventEmitter').trigger(eventName, params);
136
- break;
137
- }
138
- case LifecycleConstant.publishEvent: {
139
- const { handlerName, data: d } = data as { handlerName: string; data: unknown };
140
- lynxCoreInject.tt.publishEvent(handlerName, d);
141
- break;
142
- }
143
- }
144
- }
145
-
146
- let flushingDelayedLifecycleEvents = false;
147
- function flushDelayedLifecycleEvents(): void {
148
- // avoid stackoverflow
149
- if (flushingDelayedLifecycleEvents) return;
150
- flushingDelayedLifecycleEvents = true;
151
- if (delayedLifecycleEvents) {
152
- delayedLifecycleEvents.forEach((e) => {
153
- onLifecycleEvent(e);
154
- });
155
- delayedLifecycleEvents.length = 0;
156
- }
157
- flushingDelayedLifecycleEvents = false;
158
- }
159
-
160
- function publishEvent(handlerName: string, data: unknown) {
161
- lynxCoreInject.tt.callBeforePublishEvent?.(data);
162
- const eventHandler = backgroundSnapshotInstanceManager.getValueBySign(
163
- handlerName,
164
- );
165
- if (eventHandler) {
166
- try {
167
- (eventHandler as (...args: unknown[]) => void)(data);
168
- } catch (e) {
169
- lynx.reportError(e as Error);
170
- }
171
- }
172
- }
173
-
174
- function publicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
175
- publishEvent(handlerName, data);
176
- }
177
-
178
- function delayedPublicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
179
- delayedPublishEvent(handlerName, data);
180
- }
181
-
182
- function updateGlobalProps(newData: Record<string, any>): void {
183
- Object.assign(lynx.__globalProps, newData);
184
-
185
- // Our purpose is to make sure SYNC setState inside `emit`'s listeners
186
- // can be batched with updateFromRoot
187
- // This is already done because updateFromRoot will consume all dirty flags marked by
188
- // the setState, and setState's flush will be a noop. No extra diffs will be needed.
189
- void Promise.resolve().then(() => {
190
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
191
- runWithForce(() => render(__root.__jsx, __root as any));
192
- });
193
- lynxCoreInject.tt.GlobalEventEmitter.emit('onGlobalPropsChanged', undefined);
194
- }
195
-
196
- function updateCardData(newData: Record<string, any>, options?: Record<string, any>): void {
197
- const { ['__lynx_timing_flag']: performanceTimingFlag, ...restNewData } = newData;
198
- if (performanceTimingFlag) {
199
- lynx.reportError(
200
- new Error(
201
- `Received unsupported updateData with \`__lynx_timing_flag\` (value "${performanceTimingFlag}"), the timing flag is ignored`,
202
- ),
203
- );
204
- }
205
- const { type = NativeUpdateDataType.UPDATE } = options ?? {};
206
- if (type == NativeUpdateDataType.RESET) {
207
- lynx.__initData = {};
208
- }
209
-
210
- // COW when modify `lynx.__initData` to make sure Provider & Consumer works
211
- lynx.__initData = Object.assign({}, lynx.__initData, restNewData);
212
- lynxCoreInject.tt.GlobalEventEmitter.emit('onDataChanged', undefined);
213
- }
214
-
215
- export { injectTt, flushDelayedLifecycleEvents };