@lynx-js/react 0.105.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/CHANGELOG.md +250 -0
- package/LICENSE +202 -0
- package/README.md +20 -0
- package/components/lib/Page.d.ts +3 -0
- package/components/lib/Page.js +56 -0
- package/components/lib/Page.js.map +1 -0
- package/components/lib/index.d.ts +1 -0
- package/components/lib/index.js +5 -0
- package/components/lib/index.js.map +1 -0
- package/components/src/Page.ts +75 -0
- package/components/src/index.ts +5 -0
- package/package.json +162 -0
- package/refresh/.gitignore +1 -0
- package/refresh/.npmignore +3 -0
- package/refresh/.turbo/turbo-build.log +8 -0
- package/refresh/dist/index.js +311 -0
- package/refresh/package.json +21 -0
- package/refresh/src/index.ts +6 -0
- package/refresh/src/prefresh.d.ts +11 -0
- package/refresh/tsconfig.json +4 -0
- package/refresh/turbo.json +15 -0
- package/runtime/jsx-dev-runtime/index.d.ts +5 -0
- package/runtime/jsx-dev-runtime/index.js +4 -0
- package/runtime/jsx-runtime/index.d.ts +4 -0
- package/runtime/jsx-runtime/index.js +4 -0
- package/runtime/lazy/import.d.ts +1 -0
- package/runtime/lazy/import.js +55 -0
- package/runtime/lazy/internal.js +39 -0
- package/runtime/lazy/jsx-dev-runtime.js +12 -0
- package/runtime/lazy/jsx-runtime.js +12 -0
- package/runtime/lazy/legacy-react-runtime.js +20 -0
- package/runtime/lazy/react-lepus.js +9 -0
- package/runtime/lazy/react.js +46 -0
- package/runtime/lazy/target.js +11 -0
- package/runtime/lepus/index.d.ts +4 -0
- package/runtime/lepus/index.js +43 -0
- package/runtime/lepus/jsx-dev-runtime/index.js +4 -0
- package/runtime/lepus/jsx-runtime/index.js +66 -0
- package/runtime/lib/backgroundSnapshot.d.ts +23 -0
- package/runtime/lib/backgroundSnapshot.js +348 -0
- package/runtime/lib/backgroundSnapshot.js.map +1 -0
- package/runtime/lib/compat/componentIs.d.ts +4 -0
- package/runtime/lib/compat/componentIs.js +20 -0
- package/runtime/lib/compat/componentIs.js.map +1 -0
- package/runtime/lib/compat/initData.d.ts +43 -0
- package/runtime/lib/compat/initData.js +93 -0
- package/runtime/lib/compat/initData.js.map +1 -0
- package/runtime/lib/compat/lynxComponent.d.ts +5 -0
- package/runtime/lib/compat/lynxComponent.js +71 -0
- package/runtime/lib/compat/lynxComponent.js.map +1 -0
- package/runtime/lib/debug/debug.d.ts +2 -0
- package/runtime/lib/debug/debug.js +9 -0
- package/runtime/lib/debug/debug.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +3 -0
- package/runtime/lib/debug/printSnapshot.js +21 -0
- package/runtime/lib/debug/printSnapshot.js.map +1 -0
- package/runtime/lib/debug/profile.d.ts +1 -0
- package/runtime/lib/debug/profile.js +51 -0
- package/runtime/lib/debug/profile.js.map +1 -0
- package/runtime/lib/document.d.ts +4 -0
- package/runtime/lib/document.js +49 -0
- package/runtime/lib/document.js.map +1 -0
- package/runtime/lib/gesture/processGesture.d.ts +4 -0
- package/runtime/lib/gesture/processGesture.js +48 -0
- package/runtime/lib/gesture/processGesture.js.map +1 -0
- package/runtime/lib/gesture/processGestureBagkround.d.ts +2 -0
- package/runtime/lib/gesture/processGestureBagkround.js +16 -0
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -0
- package/runtime/lib/gesture/types.d.ts +34 -0
- package/runtime/lib/gesture/types.js +13 -0
- package/runtime/lib/gesture/types.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +26 -0
- package/runtime/lib/hooks/react.js +35 -0
- package/runtime/lib/hooks/react.js.map +1 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +29 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js +53 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js.map +1 -0
- package/runtime/lib/hydrate.d.ts +18 -0
- package/runtime/lib/hydrate.js +271 -0
- package/runtime/lib/hydrate.js.map +1 -0
- package/runtime/lib/index.d.ts +9 -0
- package/runtime/lib/index.js +46 -0
- package/runtime/lib/index.js.map +1 -0
- package/runtime/lib/internal.d.ts +26 -0
- package/runtime/lib/internal.js +41 -0
- package/runtime/lib/internal.js.map +1 -0
- package/runtime/lib/legacy-react-runtime/index.d.ts +7 -0
- package/runtime/lib/legacy-react-runtime/index.js +34 -0
- package/runtime/lib/legacy-react-runtime/index.js.map +1 -0
- package/runtime/lib/lifecycle/delayUnmount.d.ts +8 -0
- package/runtime/lib/lifecycle/delayUnmount.js +68 -0
- package/runtime/lib/lifecycle/delayUnmount.js.map +1 -0
- package/runtime/lib/lifecycle/destroy.d.ts +2 -0
- package/runtime/lib/lifecycle/destroy.js +21 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -0
- package/runtime/lib/lifecycle/pass.d.ts +3 -0
- package/runtime/lib/lifecycle/pass.js +12 -0
- package/runtime/lib/lifecycle/pass.js.map +1 -0
- package/runtime/lib/lifecycle/patchUpdate.d.ts +23 -0
- package/runtime/lib/lifecycle/patchUpdate.js +179 -0
- package/runtime/lib/lifecycle/patchUpdate.js.map +1 -0
- package/runtime/lib/lifecycle/reload.d.ts +3 -0
- package/runtime/lib/lifecycle/reload.js +63 -0
- package/runtime/lib/lifecycle/reload.js.map +1 -0
- package/runtime/lib/lifecycle/render.d.ts +2 -0
- package/runtime/lib/lifecycle/render.js +44 -0
- package/runtime/lib/lifecycle/render.js.map +1 -0
- package/runtime/lib/lifecycleConstant.d.ts +12 -0
- package/runtime/lib/lifecycleConstant.js +17 -0
- package/runtime/lib/lifecycleConstant.js.map +1 -0
- package/runtime/lib/list.d.ts +40 -0
- package/runtime/lib/list.js +305 -0
- package/runtime/lib/list.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.d.ts +2 -0
- package/runtime/lib/lynx/calledByNative.js +113 -0
- package/runtime/lib/lynx/calledByNative.js.map +1 -0
- package/runtime/lib/lynx/component.d.ts +1 -0
- package/runtime/lib/lynx/component.js +69 -0
- package/runtime/lib/lynx/component.js.map +1 -0
- package/runtime/lib/lynx/dynamic-js.d.ts +2 -0
- package/runtime/lib/lynx/dynamic-js.js +31 -0
- package/runtime/lib/lynx/dynamic-js.js.map +1 -0
- package/runtime/lib/lynx/env.d.ts +1 -0
- package/runtime/lib/lynx/env.js +92 -0
- package/runtime/lib/lynx/env.js.map +1 -0
- package/runtime/lib/lynx/injectLepusMethods.d.ts +2 -0
- package/runtime/lib/lynx/injectLepusMethods.js +50 -0
- package/runtime/lib/lynx/injectLepusMethods.js.map +1 -0
- package/runtime/lib/lynx/lazy-bundle.d.ts +9 -0
- package/runtime/lib/lynx/lazy-bundle.js +119 -0
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -0
- package/runtime/lib/lynx/performance.d.ts +29 -0
- package/runtime/lib/lynx/performance.js +100 -0
- package/runtime/lib/lynx/performance.js.map +1 -0
- package/runtime/lib/lynx/tt.d.ts +4 -0
- package/runtime/lib/lynx/tt.js +193 -0
- package/runtime/lib/lynx/tt.js.map +1 -0
- package/runtime/lib/lynx-api.d.ts +311 -0
- package/runtime/lib/lynx-api.js +116 -0
- package/runtime/lib/lynx-api.js.map +1 -0
- package/runtime/lib/lynx.d.ts +2 -0
- package/runtime/lib/lynx.js +91 -0
- package/runtime/lib/lynx.js.map +1 -0
- package/runtime/lib/opcodes.d.ts +2 -0
- package/runtime/lib/opcodes.js +59 -0
- package/runtime/lib/opcodes.js.map +1 -0
- package/runtime/lib/renderToOpcodes/constants.d.ts +17 -0
- package/runtime/lib/renderToOpcodes/constants.js +23 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.d.ts +13 -0
- package/runtime/lib/renderToOpcodes/index.js +227 -0
- package/runtime/lib/renderToOpcodes/index.js.map +1 -0
- package/runtime/lib/root.d.ts +7 -0
- package/runtime/lib/root.js +17 -0
- package/runtime/lib/root.js.map +1 -0
- package/runtime/lib/snapshot/event.d.ts +3 -0
- package/runtime/lib/snapshot/event.js +24 -0
- package/runtime/lib/snapshot/event.js.map +1 -0
- package/runtime/lib/snapshot/gesture.d.ts +2 -0
- package/runtime/lib/snapshot/gesture.js +18 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +4 -0
- package/runtime/lib/snapshot/platformInfo.js +35 -0
- package/runtime/lib/snapshot/platformInfo.js.map +1 -0
- package/runtime/lib/snapshot/ref.d.ts +10 -0
- package/runtime/lib/snapshot/ref.js +119 -0
- package/runtime/lib/snapshot/ref.js.map +1 -0
- package/runtime/lib/snapshot/spread.d.ts +5 -0
- package/runtime/lib/snapshot/spread.js +289 -0
- package/runtime/lib/snapshot/spread.js.map +1 -0
- package/runtime/lib/snapshot/workletEvent.d.ts +3 -0
- package/runtime/lib/snapshot/workletEvent.js +22 -0
- package/runtime/lib/snapshot/workletEvent.js.map +1 -0
- package/runtime/lib/snapshot/workletRef.d.ts +5 -0
- package/runtime/lib/snapshot/workletRef.js +52 -0
- package/runtime/lib/snapshot/workletRef.js.map +1 -0
- package/runtime/lib/snapshot.d.ts +81 -0
- package/runtime/lib/snapshot.js +477 -0
- package/runtime/lib/snapshot.js.map +1 -0
- package/runtime/lib/snapshotPatch.d.ts +14 -0
- package/runtime/lib/snapshotPatch.js +31 -0
- package/runtime/lib/snapshotPatch.js.map +1 -0
- package/runtime/lib/snapshotPatchApply.d.ts +2 -0
- package/runtime/lib/snapshotPatchApply.js +110 -0
- package/runtime/lib/snapshotPatchApply.js.map +1 -0
- package/runtime/lib/utils.d.ts +4 -0
- package/runtime/lib/utils.js +32 -0
- package/runtime/lib/utils.js.map +1 -0
- package/runtime/lib/worklet/ctx.d.ts +1 -0
- package/runtime/lib/worklet/ctx.js +17 -0
- package/runtime/lib/worklet/ctx.js.map +1 -0
- package/runtime/lib/worklet/execMap.d.ts +1 -0
- package/runtime/lib/worklet/execMap.js +42 -0
- package/runtime/lib/worklet/execMap.js.map +1 -0
- package/runtime/lib/worklet/functionality.d.ts +1 -0
- package/runtime/lib/worklet/functionality.js +11 -0
- package/runtime/lib/worklet/functionality.js.map +1 -0
- package/runtime/lib/worklet/hmr.d.ts +1 -0
- package/runtime/lib/worklet/hmr.js +21 -0
- package/runtime/lib/worklet/hmr.js.map +1 -0
- package/runtime/lib/worklet/indexMap.d.ts +8 -0
- package/runtime/lib/worklet/indexMap.js +17 -0
- package/runtime/lib/worklet/indexMap.js.map +1 -0
- package/runtime/lib/worklet/jsImpl.d.ts +11 -0
- package/runtime/lib/worklet/jsImpl.js +68 -0
- package/runtime/lib/worklet/jsImpl.js.map +1 -0
- package/runtime/lib/worklet/runWorklet.d.ts +14 -0
- package/runtime/lib/worklet/runWorklet.js +82 -0
- package/runtime/lib/worklet/runWorklet.js.map +1 -0
- package/runtime/lib/worklet/workletRef.d.ts +131 -0
- package/runtime/lib/worklet/workletRef.js +96 -0
- package/runtime/lib/worklet/workletRef.js.map +1 -0
- package/runtime/lib/worklet/workletRefPool.d.ts +2 -0
- package/runtime/lib/worklet/workletRefPool.js +22 -0
- package/runtime/lib/worklet/workletRefPool.js.map +1 -0
- package/runtime/src/backgroundSnapshot.ts +452 -0
- package/runtime/src/compat/componentIs.ts +30 -0
- package/runtime/src/compat/initData.ts +140 -0
- package/runtime/src/compat/lynxComponent.ts +80 -0
- package/runtime/src/debug/debug.ts +9 -0
- package/runtime/src/debug/printSnapshot.ts +28 -0
- package/runtime/src/debug/profile.ts +54 -0
- package/runtime/src/document.ts +53 -0
- package/runtime/src/gesture/processGesture.ts +77 -0
- package/runtime/src/gesture/processGestureBagkround.ts +15 -0
- package/runtime/src/gesture/types.ts +39 -0
- package/runtime/src/hooks/react.ts +62 -0
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +59 -0
- package/runtime/src/hydrate.ts +364 -0
- package/runtime/src/index.ts +89 -0
- package/runtime/src/internal.ts +60 -0
- package/runtime/src/legacy-react-runtime/index.ts +40 -0
- package/runtime/src/lifecycle/delayUnmount.ts +77 -0
- package/runtime/src/lifecycle/destroy.ts +26 -0
- package/runtime/src/lifecycle/pass.ts +14 -0
- package/runtime/src/lifecycle/patchUpdate.ts +240 -0
- package/runtime/src/lifecycle/reload.ts +79 -0
- package/runtime/src/lifecycle/render.ts +46 -0
- package/runtime/src/lifecycleConstant.ts +16 -0
- package/runtime/src/list.ts +375 -0
- package/runtime/src/lynx/calledByNative.ts +132 -0
- package/runtime/src/lynx/component.ts +116 -0
- package/runtime/src/lynx/dynamic-js.ts +33 -0
- package/runtime/src/lynx/env.ts +110 -0
- package/runtime/src/lynx/injectLepusMethods.ts +53 -0
- package/runtime/src/lynx/lazy-bundle.ts +126 -0
- package/runtime/src/lynx/performance.ts +117 -0
- package/runtime/src/lynx/tt.ts +212 -0
- package/runtime/src/lynx-api.ts +374 -0
- package/runtime/src/lynx.ts +105 -0
- package/runtime/src/opcodes.ts +64 -0
- package/runtime/src/renderToOpcodes/constants.ts +24 -0
- package/runtime/src/renderToOpcodes/index.ts +301 -0
- package/runtime/src/root.ts +19 -0
- package/runtime/src/snapshot/event.ts +33 -0
- package/runtime/src/snapshot/gesture.ts +25 -0
- package/runtime/src/snapshot/platformInfo.ts +48 -0
- package/runtime/src/snapshot/ref.ts +151 -0
- package/runtime/src/snapshot/spread.ts +287 -0
- package/runtime/src/snapshot/workletEvent.ts +33 -0
- package/runtime/src/snapshot/workletRef.ts +63 -0
- package/runtime/src/snapshot.ts +576 -0
- package/runtime/src/snapshotPatch.ts +56 -0
- package/runtime/src/snapshotPatchApply.ts +117 -0
- package/runtime/src/utils.ts +35 -0
- package/runtime/src/worklet/ctx.ts +22 -0
- package/runtime/src/worklet/execMap.ts +50 -0
- package/runtime/src/worklet/functionality.ts +12 -0
- package/runtime/src/worklet/hmr.ts +26 -0
- package/runtime/src/worklet/indexMap.ts +20 -0
- package/runtime/src/worklet/jsImpl.ts +86 -0
- package/runtime/src/worklet/runWorklet.ts +88 -0
- package/runtime/src/worklet/workletRef.ts +229 -0
- package/runtime/src/worklet/workletRefPool.ts +25 -0
- package/transform/cjs/main.cjs +6 -0
- package/transform/cjs/main.d.cts +3 -0
- package/transform/cjs/package.json +3 -0
- package/transform/dist/wasm.cjs +8478 -0
- package/transform/index.d.ts +187 -0
- package/transform/main.js +15 -0
- package/types/react.d.ts +147 -0
- package/types/react.docs.d.ts +74 -0
- package/worklet-runtime/dist/dev.js +414 -0
- package/worklet-runtime/dist/dev.js.map +8 -0
- package/worklet-runtime/dist/main.js +414 -0
- package/worklet-runtime/dist/main.js.map +8 -0
- package/worklet-runtime/lib/api/element.d.ts +14 -0
- package/worklet-runtime/lib/api/element.js +71 -0
- package/worklet-runtime/lib/api/element.js.map +1 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.d.ts +3 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js +23 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -0
- package/worklet-runtime/lib/api/lynxApi.d.ts +2 -0
- package/worklet-runtime/lib/api/lynxApi.js +35 -0
- package/worklet-runtime/lib/api/lynxApi.js.map +1 -0
- package/worklet-runtime/lib/bindings/bindings.d.ts +14 -0
- package/worklet-runtime/lib/bindings/bindings.js +61 -0
- package/worklet-runtime/lib/bindings/bindings.js.map +1 -0
- package/worklet-runtime/lib/bindings/events.d.ts +7 -0
- package/worklet-runtime/lib/bindings/events.js +9 -0
- package/worklet-runtime/lib/bindings/events.js.map +1 -0
- package/worklet-runtime/lib/bindings/index.d.ts +4 -0
- package/worklet-runtime/lib/bindings/index.js +7 -0
- package/worklet-runtime/lib/bindings/index.js.map +1 -0
- package/worklet-runtime/lib/bindings/loadRuntime.d.ts +8 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js +25 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -0
- package/worklet-runtime/lib/bindings/types.d.ts +35 -0
- package/worklet-runtime/lib/bindings/types.js +2 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -0
- package/worklet-runtime/lib/delayWorkletEvent.d.ts +11 -0
- package/worklet-runtime/lib/delayWorkletEvent.js +49 -0
- package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -0
- package/worklet-runtime/lib/global.d.ts +15 -0
- package/worklet-runtime/lib/global.js +2 -0
- package/worklet-runtime/lib/global.js.map +1 -0
- package/worklet-runtime/lib/index.d.ts +1 -0
- package/worklet-runtime/lib/index.js +12 -0
- package/worklet-runtime/lib/index.js.map +1 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +18 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js +55 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -0
- package/worklet-runtime/lib/listeners.d.ts +2 -0
- package/worklet-runtime/lib/listeners.js +17 -0
- package/worklet-runtime/lib/listeners.js.map +1 -0
- package/worklet-runtime/lib/utils/profile.d.ts +1 -0
- package/worklet-runtime/lib/utils/profile.js +20 -0
- package/worklet-runtime/lib/utils/profile.js.map +1 -0
- package/worklet-runtime/lib/utils/version.d.ts +1 -0
- package/worklet-runtime/lib/utils/version.js +10 -0
- package/worklet-runtime/lib/utils/version.js.map +1 -0
- package/worklet-runtime/lib/workletRef.d.ts +12 -0
- package/worklet-runtime/lib/workletRef.js +50 -0
- package/worklet-runtime/lib/workletRef.js.map +1 -0
- package/worklet-runtime/lib/workletRuntime.d.ts +2 -0
- package/worklet-runtime/lib/workletRuntime.js +128 -0
- package/worklet-runtime/lib/workletRuntime.js.map +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
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 type { DataProcessorDefinition } from '../lynx-api.js';
|
|
5
|
+
|
|
6
|
+
export function setupLynxEnv(): void {
|
|
7
|
+
if (!__LEPUS__) {
|
|
8
|
+
const { initData, updateData } = lynxCoreInject.tt._params;
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
lynx.__initData = { ...initData, ...updateData };
|
|
11
|
+
lynx.registerDataProcessors = function() {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (__LEPUS__) {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
lynx.__initData = {
|
|
17
|
+
/* available only in renderPage */
|
|
18
|
+
};
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
globalThis.SystemInfo = lynx.SystemInfo || {};
|
|
21
|
+
|
|
22
|
+
lynx.reportError = function(e: any) {
|
|
23
|
+
_ReportError(e, {
|
|
24
|
+
errorCode: 1101, // ErrCode::LYNX_ERROR_CODE_LEPUS in Lynx/base/debug/error_code.h
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
lynx.triggerGlobalEventFromLepus = function(
|
|
29
|
+
eventName: string,
|
|
30
|
+
params: any,
|
|
31
|
+
) {
|
|
32
|
+
__OnLifecycleEvent(['globalEventFromLepus', [eventName, params]]);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
function __name(empty: string) {
|
|
37
|
+
return `Native${empty}Modules`;
|
|
38
|
+
}
|
|
39
|
+
// TODO(hongzhiyuan.hzy): make sure this is run before any other code (especially code access `NativeModules`)
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
if (typeof globalThis[__name('')] === 'undefined') {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
globalThis[__name('')] = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
lynx.registerDataProcessors = function(
|
|
48
|
+
dataProcessorDefinition?: DataProcessorDefinition,
|
|
49
|
+
) {
|
|
50
|
+
let hasDefaultDataProcessorExecuted = false;
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
globalThis.processData = (data, processorName) => {
|
|
53
|
+
if (__PROFILE__) {
|
|
54
|
+
console.profile('processData');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let r;
|
|
58
|
+
try {
|
|
59
|
+
if (processorName) {
|
|
60
|
+
r = dataProcessorDefinition?.dataProcessors?.[processorName]?.(data)
|
|
61
|
+
?? data;
|
|
62
|
+
} else {
|
|
63
|
+
r = dataProcessorDefinition?.defaultDataProcessor?.(data) ?? data;
|
|
64
|
+
}
|
|
65
|
+
} catch (e: any) {
|
|
66
|
+
lynx.reportError(e);
|
|
67
|
+
// when there is an error
|
|
68
|
+
// we should perform like dataProcessor returns nothing
|
|
69
|
+
// so use `{}` rather than `data`
|
|
70
|
+
r = {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (__PROFILE__) {
|
|
74
|
+
console.profileEnd();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (hasDefaultDataProcessorExecuted === false) {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
if (globalThis.__I18N_RESOURCE_TRANSLATION__) {
|
|
80
|
+
r = {
|
|
81
|
+
...r,
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
__I18N_RESOURCE_TRANSLATION__: globalThis.__I18N_RESOURCE_TRANSLATION__,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
if (__EXTRACT_STR__) {
|
|
89
|
+
r = {
|
|
90
|
+
...r,
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
_EXTRACT_STR: __EXTRACT_STR_IDENT_FLAG__,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (processorName) {
|
|
98
|
+
} else {
|
|
99
|
+
hasDefaultDataProcessorExecuted = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return r;
|
|
103
|
+
// TODO
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// register empty DataProcessors to make sure `globalThis.processData` is set
|
|
108
|
+
lynx.registerDataProcessors();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { snapshotInstanceManager } from '../snapshot.js';
|
|
5
|
+
|
|
6
|
+
function injectLepusMethods(): void {
|
|
7
|
+
Object.assign(globalThis, {
|
|
8
|
+
getUniqueIdListBySnapshotId,
|
|
9
|
+
getSnapshotIdByUniqueId,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get the list of `unique_id` of the fiber element by the SnapshotInstance `__id`.
|
|
15
|
+
*/
|
|
16
|
+
function getUniqueIdListBySnapshotId({ snapshotId }: { snapshotId: number }) {
|
|
17
|
+
const si = snapshotInstanceManager.values.get(snapshotId);
|
|
18
|
+
if (si?.__elements?.length) {
|
|
19
|
+
const uniqueIdList = [];
|
|
20
|
+
for (const element of si.__elements) {
|
|
21
|
+
const uniqueId = __GetElementUniqueID(element);
|
|
22
|
+
uniqueIdList.push(uniqueId);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
uniqueIdList,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the SnapshotInstance `__id` of the fiber element by the `unique_id`.
|
|
33
|
+
*/
|
|
34
|
+
function getSnapshotIdByUniqueId({ uniqueId }: { uniqueId: number }) {
|
|
35
|
+
for (const si of snapshotInstanceManager.values.values()) {
|
|
36
|
+
if (si?.__elements?.length) {
|
|
37
|
+
for (const element of si.__elements) {
|
|
38
|
+
const unique_id = __GetElementUniqueID(element);
|
|
39
|
+
if (unique_id === uniqueId) {
|
|
40
|
+
return {
|
|
41
|
+
snapshotId: si.__id,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export { injectLepusMethods };
|
|
@@ -0,0 +1,126 @@
|
|
|
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 { Fragment, lazy as backgroundLazy, createElement } from 'preact/compat';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* To make code below works
|
|
8
|
+
* const App1 = lazy(() => import("./x").then(({App1}) => ({default: App1})))
|
|
9
|
+
* const App2 = lazy(() => import("./x").then(({App2}) => ({default: App2})))
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const makeSyncThen = function<T>(result: T) {
|
|
13
|
+
return function(this: Promise<T>, onF?: Function): Promise<T> {
|
|
14
|
+
if (onF) {
|
|
15
|
+
let ret;
|
|
16
|
+
try {
|
|
17
|
+
ret = onF(result);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
if (ret && typeof ret.then === 'function' /* `thenable` object */) {
|
|
24
|
+
// lazy(() =>
|
|
25
|
+
// import("./x").then(() => new Promise(...))
|
|
26
|
+
// )
|
|
27
|
+
// Calling `then` and passing a callback is standard behavior
|
|
28
|
+
// but in Lepus runtime the callback will never be called
|
|
29
|
+
// So can be simplified to code below
|
|
30
|
+
return new Promise(() => {});
|
|
31
|
+
|
|
32
|
+
// TODO(hongzhiyuan.hzy): Avoid warning that cannot be turned-off, so the warning is commented
|
|
33
|
+
// lynx.reportError(
|
|
34
|
+
// new Error(
|
|
35
|
+
// 'You returned a Promise in promise-chain of lazy-bundle import (eg. `import("./x").then(() => new Promise(...))`), which will cause related Component unavailable at first-screen, '
|
|
36
|
+
// ),
|
|
37
|
+
// { level: "warning" }
|
|
38
|
+
// );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const p = Promise.resolve(ret);
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
p.then = makeSyncThen(ret);
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return this;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Load dynamic component from source. Designed to be used with `lazy`.
|
|
53
|
+
* @param source - where dynamic component template.js locates
|
|
54
|
+
* @returns
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export function loadLazyBundle<
|
|
58
|
+
T extends { default: React.ComponentType<any> },
|
|
59
|
+
>(source: string): Promise<T> {
|
|
60
|
+
if (__LEPUS__) {
|
|
61
|
+
const query = __QueryComponent(source);
|
|
62
|
+
let result: T;
|
|
63
|
+
try {
|
|
64
|
+
result = query.evalResult;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
// Here we cannot return a rejected promise
|
|
67
|
+
// (which will eventually be an unhandled rejection and cause unnecessary redbox)
|
|
68
|
+
// But we still need a object in shape of Promise
|
|
69
|
+
// So we return a Promise which will never resolve or reject,
|
|
70
|
+
// which fit our principle "lepus run only once at first-screen" better
|
|
71
|
+
return new Promise(() => {});
|
|
72
|
+
}
|
|
73
|
+
const r: Promise<T> = Promise.resolve(result);
|
|
74
|
+
// Why we should modify the implementation of `then`?
|
|
75
|
+
// We should make it `sync` so lepus first-screen render can use result above instantly
|
|
76
|
+
// We also should keep promise shape
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
r.then = makeSyncThen(result);
|
|
79
|
+
return r;
|
|
80
|
+
} else if (__JS__) {
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const callback: (result: any) => void = result => {
|
|
83
|
+
const { code, detail } = result;
|
|
84
|
+
if (code === 0) {
|
|
85
|
+
const { schema } = detail;
|
|
86
|
+
const exports = lynxCoreInject.tt.getDynamicComponentExports(schema);
|
|
87
|
+
// `code === 0` means that the lazy bundle has been successfully parsed. However,
|
|
88
|
+
// its javascript files may still fail to run, which would prevent the retrieval of the exports object.
|
|
89
|
+
if (exports) {
|
|
90
|
+
resolve(exports);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
reject(new Error('Lazy bundle load failed: ' + JSON.stringify(result)));
|
|
95
|
+
};
|
|
96
|
+
if (typeof lynx.QueryComponent === 'function') {
|
|
97
|
+
lynx.QueryComponent(source, callback);
|
|
98
|
+
} else {
|
|
99
|
+
lynx.getNativeLynx().QueryComponent(source, callback);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw new Error('unreachable');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
lynx.loadLazyBundle = loadLazyBundle;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export function mainThreadLazy<T>(loader: () => Promise<{ default: T } | T>) {
|
|
113
|
+
const Lazy = backgroundLazy<T>(loader);
|
|
114
|
+
|
|
115
|
+
function _Lazy(props: any) {
|
|
116
|
+
try {
|
|
117
|
+
// @ts-expect-error `Lazy` returned from `backgroundLazy` should be a FC
|
|
118
|
+
return Lazy(props);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
// We should never throw at mainThread
|
|
121
|
+
return createElement(Fragment, {});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return _Lazy as T;
|
|
126
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
import { DIFF } from '../renderToOpcodes/constants.js';
|
|
7
|
+
import { __globalSnapshotPatch } from '../snapshotPatch.js';
|
|
8
|
+
|
|
9
|
+
enum PerformanceTimingKeys {
|
|
10
|
+
update_set_state_trigger,
|
|
11
|
+
update_diff_vdom_start,
|
|
12
|
+
update_diff_vdom_end,
|
|
13
|
+
// update_set_state_trigger, update_diff_vdom_start and update_diff_vdom_end is deprecated
|
|
14
|
+
diff_vdom_start,
|
|
15
|
+
diff_vdom_end,
|
|
16
|
+
pack_changes_start,
|
|
17
|
+
pack_changes_end,
|
|
18
|
+
parse_changes_start,
|
|
19
|
+
parse_changes_end,
|
|
20
|
+
patch_changes_start,
|
|
21
|
+
patch_changes_end,
|
|
22
|
+
hydrate_parse_snapshot_start,
|
|
23
|
+
hydrate_parse_snapshot_end,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated used by old timing api(setState timing flag)
|
|
28
|
+
*/
|
|
29
|
+
const PerfSpecificKey = '__lynx_timing_flag';
|
|
30
|
+
let timingFlag: string | undefined;
|
|
31
|
+
let shouldMarkDiffVdomStart = false;
|
|
32
|
+
let shouldMarkDiffVdomEnd = false;
|
|
33
|
+
|
|
34
|
+
let globalPipelineOptions: PipelineOptions | undefined;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated used by old timing api(setState timing flag)
|
|
38
|
+
*/
|
|
39
|
+
function markTimingLegacy(key: PerformanceTimingKeys, timingFlag_?: string): void {
|
|
40
|
+
switch (key) {
|
|
41
|
+
case PerformanceTimingKeys.update_set_state_trigger: {
|
|
42
|
+
shouldMarkDiffVdomStart = true;
|
|
43
|
+
shouldMarkDiffVdomEnd = true;
|
|
44
|
+
timingFlag = timingFlag_;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case PerformanceTimingKeys.update_diff_vdom_start: {
|
|
48
|
+
/* v8 ignore start */
|
|
49
|
+
if (!shouldMarkDiffVdomStart) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
/* v8 ignore stop */
|
|
53
|
+
shouldMarkDiffVdomStart = false;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case PerformanceTimingKeys.update_diff_vdom_end: {
|
|
57
|
+
if (!shouldMarkDiffVdomEnd) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
shouldMarkDiffVdomEnd = false;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
lynx.getNativeApp().markTiming?.(timingFlag, PerformanceTimingKeys[key]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function beginPipeline(needTimestamps: boolean, timingFlag?: string): void {
|
|
68
|
+
globalPipelineOptions = lynx.performance?._generatePipelineOptions?.();
|
|
69
|
+
if (globalPipelineOptions) {
|
|
70
|
+
globalPipelineOptions.needTimestamps = needTimestamps;
|
|
71
|
+
lynx.performance?._onPipelineStart?.(globalPipelineOptions.pipelineID);
|
|
72
|
+
if (timingFlag) {
|
|
73
|
+
lynx.performance?._bindPipelineIdWithTimingFlag?.(globalPipelineOptions.pipelineID, timingFlag);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function setPipeline(pipeline: PipelineOptions | undefined): void {
|
|
79
|
+
globalPipelineOptions = pipeline;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function markTiming(timestampKey: PerformanceTimingKeys, force?: boolean): void {
|
|
83
|
+
if (globalPipelineOptions && (force || globalPipelineOptions.needTimestamps)) {
|
|
84
|
+
lynx.performance?._markTiming?.(globalPipelineOptions.pipelineID, PerformanceTimingKeys[timestampKey]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function initTimingAPI(): void {
|
|
89
|
+
const oldDiff = options[DIFF];
|
|
90
|
+
options[DIFF] = (vnode: VNode) => {
|
|
91
|
+
// check `__globalSnapshotPatch` to make sure this only runs after hydrate
|
|
92
|
+
if (__JS__ && __globalSnapshotPatch) {
|
|
93
|
+
if (!globalPipelineOptions) {
|
|
94
|
+
beginPipeline(false);
|
|
95
|
+
markTiming(PerformanceTimingKeys.diff_vdom_start, true);
|
|
96
|
+
}
|
|
97
|
+
if (shouldMarkDiffVdomStart) {
|
|
98
|
+
markTimingLegacy(PerformanceTimingKeys.update_diff_vdom_start);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
oldDiff?.(vnode);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
export {
|
|
109
|
+
PerformanceTimingKeys,
|
|
110
|
+
PerfSpecificKey,
|
|
111
|
+
markTimingLegacy,
|
|
112
|
+
initTimingAPI,
|
|
113
|
+
beginPipeline,
|
|
114
|
+
markTiming,
|
|
115
|
+
setPipeline,
|
|
116
|
+
globalPipelineOptions,
|
|
117
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
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 { PerformanceTimingKeys, beginPipeline, markTiming } from './performance.js';
|
|
8
|
+
import { BackgroundSnapshotInstance, hydrate } from '../backgroundSnapshot.js';
|
|
9
|
+
import { destroyBackground } from '../lifecycle/destroy.js';
|
|
10
|
+
import { commitPatchUpdate, genCommitTaskId, globalCommitTaskMap } from '../lifecycle/patchUpdate.js';
|
|
11
|
+
import { reloadBackground } from '../lifecycle/reload.js';
|
|
12
|
+
import { runWithForce } from '../lynx.js';
|
|
13
|
+
import { CHILDREN } from '../renderToOpcodes/constants.js';
|
|
14
|
+
import { __root } from '../root.js';
|
|
15
|
+
import { globalRefsToSet, updateBackgroundRefs } from '../snapshot/ref.js';
|
|
16
|
+
import { backgroundSnapshotInstanceManager } from '../snapshot.js';
|
|
17
|
+
import { destroyWorklet } from '../worklet/jsImpl.js';
|
|
18
|
+
|
|
19
|
+
function injectTt(): void {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const tt = lynxCoreInject.tt;
|
|
22
|
+
tt.OnLifecycleEvent = OnLifecycleEvent;
|
|
23
|
+
tt.publishEvent = delayedPublishEvent;
|
|
24
|
+
tt.publicComponentEvent = delayedPublicComponentEvent;
|
|
25
|
+
tt.callDestroyLifetimeFun = () => {
|
|
26
|
+
destroyWorklet();
|
|
27
|
+
destroyBackground();
|
|
28
|
+
};
|
|
29
|
+
tt.updateGlobalProps = updateGlobalProps;
|
|
30
|
+
tt.updateCardData = updateCardData;
|
|
31
|
+
tt.onAppReload = reloadBackground;
|
|
32
|
+
tt.processCardConfig = () => {
|
|
33
|
+
// used to updateTheme, no longer rely on this function
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let delayedLifecycleEvents: [type: string, data: any][];
|
|
38
|
+
async function OnLifecycleEvent([type, data]: [string, any]) {
|
|
39
|
+
const hasRootRendered = CHILDREN in __root;
|
|
40
|
+
// never called `render(<App/>, __root)`
|
|
41
|
+
// happens if user call `root.render()` async
|
|
42
|
+
if (!hasRootRendered) {
|
|
43
|
+
delayedLifecycleEvents ??= [];
|
|
44
|
+
delayedLifecycleEvents.push([type, data]);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (__PROFILE__) {
|
|
49
|
+
console.profile(`OnLifecycleEvent::${type}`);
|
|
50
|
+
}
|
|
51
|
+
switch (type) {
|
|
52
|
+
case LifecycleConstant.firstScreen: {
|
|
53
|
+
const { root: lepusSide, refPatch, jsReadyEventIdSwap } = data;
|
|
54
|
+
if (__PROFILE__) {
|
|
55
|
+
console.profile('hydrate');
|
|
56
|
+
}
|
|
57
|
+
beginPipeline(true, 'react_lynx_hydrate');
|
|
58
|
+
markTiming(PerformanceTimingKeys.hydrate_parse_snapshot_start);
|
|
59
|
+
const before = JSON.parse(lepusSide);
|
|
60
|
+
markTiming(PerformanceTimingKeys.hydrate_parse_snapshot_end);
|
|
61
|
+
markTiming(PerformanceTimingKeys.diff_vdom_start);
|
|
62
|
+
const snapshotPatch = hydrate(
|
|
63
|
+
before,
|
|
64
|
+
__root as BackgroundSnapshotInstance,
|
|
65
|
+
);
|
|
66
|
+
if (__PROFILE__) {
|
|
67
|
+
console.profileEnd();
|
|
68
|
+
}
|
|
69
|
+
markTiming(PerformanceTimingKeys.diff_vdom_end);
|
|
70
|
+
|
|
71
|
+
if (delayedEvents) {
|
|
72
|
+
delayedEvents.forEach((args) => {
|
|
73
|
+
const [handlerName, data] = args;
|
|
74
|
+
let [idStr, ...rest] = handlerName.split(':');
|
|
75
|
+
while (jsReadyEventIdSwap[idStr!]) idStr = jsReadyEventIdSwap[idStr!];
|
|
76
|
+
try {
|
|
77
|
+
publishEvent([idStr, ...rest].join(':'), data);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
lynx.reportError(e);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
delayedEvents.length = 0;
|
|
83
|
+
}
|
|
84
|
+
lynxCoreInject.tt.publishEvent = publishEvent;
|
|
85
|
+
lynxCoreInject.tt.publicComponentEvent = publicComponentEvent;
|
|
86
|
+
|
|
87
|
+
if (__PROFILE__) {
|
|
88
|
+
console.profile('patchRef');
|
|
89
|
+
}
|
|
90
|
+
if (refPatch) {
|
|
91
|
+
globalRefsToSet.set(0, JSON.parse(refPatch));
|
|
92
|
+
updateBackgroundRefs(0);
|
|
93
|
+
}
|
|
94
|
+
if (__PROFILE__) {
|
|
95
|
+
console.profileEnd();
|
|
96
|
+
}
|
|
97
|
+
markTiming(PerformanceTimingKeys.pack_changes_start);
|
|
98
|
+
// console.debug("********** After hydration:");
|
|
99
|
+
// printSnapshotInstance(__root as BackgroundSnapshotInstance);
|
|
100
|
+
if (__PROFILE__) {
|
|
101
|
+
console.profile('commitChanges');
|
|
102
|
+
}
|
|
103
|
+
const commitTaskId = genCommitTaskId();
|
|
104
|
+
await commitPatchUpdate({ snapshotPatch }, { commitTaskId, isHydration: true });
|
|
105
|
+
updateBackgroundRefs(commitTaskId);
|
|
106
|
+
globalCommitTaskMap.forEach((commitTask, id) => {
|
|
107
|
+
if (id > commitTaskId) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
commitTask();
|
|
111
|
+
globalCommitTaskMap.delete(id);
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case LifecycleConstant.globalEventFromLepus: {
|
|
116
|
+
const [eventName, params] = data;
|
|
117
|
+
lynx.getJSModule('GlobalEventEmitter').trigger(eventName, params);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case LifecycleConstant.ref: {
|
|
121
|
+
const { refPatch, commitTaskId } = data;
|
|
122
|
+
if (commitTaskId) {
|
|
123
|
+
globalRefsToSet.set(commitTaskId, JSON.parse(refPatch));
|
|
124
|
+
} else {
|
|
125
|
+
globalRefsToSet.set(0, JSON.parse(refPatch));
|
|
126
|
+
updateBackgroundRefs(0);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (__PROFILE__) {
|
|
132
|
+
console.profileEnd();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function flushDelayedLifecycleEvents(): void {
|
|
137
|
+
if (delayedLifecycleEvents) {
|
|
138
|
+
delayedLifecycleEvents.forEach((e) => {
|
|
139
|
+
try {
|
|
140
|
+
OnLifecycleEvent(e);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
lynx.reportError(e);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
delayedLifecycleEvents.length = 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function publishEvent(handlerName: string, data: unknown) {
|
|
150
|
+
// TODO: delay js events until js ready
|
|
151
|
+
lynxCoreInject.tt.callBeforePublishEvent?.(data);
|
|
152
|
+
const eventHandler = backgroundSnapshotInstanceManager.getValueBySign(
|
|
153
|
+
handlerName,
|
|
154
|
+
);
|
|
155
|
+
if (eventHandler) {
|
|
156
|
+
try {
|
|
157
|
+
(eventHandler as Function)(data);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
lynx.reportError(e as Error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function publicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
|
|
165
|
+
publishEvent(handlerName, data);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let delayedEvents: [handlerName: string, data: unknown][];
|
|
169
|
+
function delayedPublishEvent(handlerName: string, data: unknown) {
|
|
170
|
+
delayedEvents ??= [];
|
|
171
|
+
delayedEvents.push([handlerName, data]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function delayedPublicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
|
|
175
|
+
delayedPublishEvent(handlerName, data);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function updateGlobalProps(newData: Record<string, any>): void {
|
|
179
|
+
Object.assign(lynx.__globalProps, newData);
|
|
180
|
+
|
|
181
|
+
// Our purpose is to make sure SYNC setState inside `emit`'s listeners
|
|
182
|
+
// can be batched with updateFromRoot
|
|
183
|
+
// This is already done because updateFromRoot will consume all dirty flags marked by
|
|
184
|
+
// the setState, and setState's flush will be a noop. No extra diffs will be needed.
|
|
185
|
+
Promise.resolve().then(() => {
|
|
186
|
+
runWithForce(() => render(__root.__jsx, __root as any));
|
|
187
|
+
});
|
|
188
|
+
lynxCoreInject.tt.GlobalEventEmitter.emit('onGlobalPropsChanged');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function updateCardData(newData: Record<string, any>, options?: Record<string, any>): void {
|
|
192
|
+
const { ['__lynx_timing_flag']: performanceTimingFlag, ...restNewData } = newData;
|
|
193
|
+
if (performanceTimingFlag) {
|
|
194
|
+
lynx.reportError(
|
|
195
|
+
new Error(
|
|
196
|
+
`Received unsupported updateData with \`__lynx_timing_flag\` (value "${performanceTimingFlag}"), the timing flag is ignored`,
|
|
197
|
+
),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
const { type = NativeUpdateDataType.UPDATE } = options || {};
|
|
201
|
+
if (type == NativeUpdateDataType.RESET) {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
lynx.__initData = {};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// COW when modify `lynx.__initData` to make sure Provider & Consumer works
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
lynx.__initData = Object.assign({}, lynx.__initData, restNewData);
|
|
209
|
+
lynxCoreInject.tt.GlobalEventEmitter.emit('onDataChanged');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { injectTt, flushDelayedLifecycleEvents, delayedLifecycleEvents };
|