@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,375 @@
|
|
|
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 { hydrate } from './hydrate.js';
|
|
5
|
+
import { commitMainThreadPatchUpdate } from './lifecycle/patchUpdate.js';
|
|
6
|
+
import type { SnapshotInstance } from './snapshot.js';
|
|
7
|
+
|
|
8
|
+
export interface ListUpdateInfo {
|
|
9
|
+
flush(): void;
|
|
10
|
+
onInsertBefore(
|
|
11
|
+
newNode: SnapshotInstance,
|
|
12
|
+
existingNode?: SnapshotInstance,
|
|
13
|
+
): void;
|
|
14
|
+
onRemoveChild(child: SnapshotInstance): void;
|
|
15
|
+
onSetAttribute(child: SnapshotInstance, attr: any, oldAttr: any): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface UpdateAction {
|
|
19
|
+
insertAction: {
|
|
20
|
+
position: number;
|
|
21
|
+
type: string;
|
|
22
|
+
}[];
|
|
23
|
+
removeAction: number[];
|
|
24
|
+
// TODO: type `updateAction`
|
|
25
|
+
updateAction: any[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// class ListUpdateInfoDiffing implements ListUpdateInfo {
|
|
29
|
+
// private oldChildNodes: SnapshotInstance[];
|
|
30
|
+
// constructor(private list: SnapshotInstance) {
|
|
31
|
+
// this.oldChildNodes = list.childNodes;
|
|
32
|
+
// }
|
|
33
|
+
// flush(): void {
|
|
34
|
+
// Object.defineProperty(SnapshotInstance.prototype, "key", {
|
|
35
|
+
// get: function () {
|
|
36
|
+
// return this.values[0]["item-key"];
|
|
37
|
+
// },
|
|
38
|
+
// });
|
|
39
|
+
|
|
40
|
+
// }
|
|
41
|
+
// onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance | undefined): void {}
|
|
42
|
+
// onRemoveChild(child: SnapshotInstance): void {}
|
|
43
|
+
// onSetAttribute(child: SnapshotInstance, attr: any): void {
|
|
44
|
+
// throw new Error("Method not implemented.");
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
export class ListUpdateInfoRecording implements ListUpdateInfo {
|
|
49
|
+
constructor(private list: SnapshotInstance) {
|
|
50
|
+
this.oldChildNodes = list.childNodes;
|
|
51
|
+
// this.oldChildNodesSet = new Set(this.oldChildNodes);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// private __commitAndReset() {
|
|
55
|
+
// (this.__pendingAttributes ??= []).push(this.__toAttribute());
|
|
56
|
+
// this.oldChildNodes = this.list.childNodes;
|
|
57
|
+
// this.oldChildNodesSet = new Set(this.oldChildNodes);
|
|
58
|
+
// this.removeChild1.clear();
|
|
59
|
+
// this.removeChild2.clear();
|
|
60
|
+
// this.insertBefore.clear();
|
|
61
|
+
// this.appendChild.length = 0;
|
|
62
|
+
// this.platformInfoUpdate.clear();
|
|
63
|
+
// }
|
|
64
|
+
|
|
65
|
+
flush(): void {
|
|
66
|
+
const elementIndex = this.list.__snapshot_def.slot[0]![1];
|
|
67
|
+
const listElement = this.list.__elements![elementIndex]!;
|
|
68
|
+
// this.__pendingAttributes?.forEach(pendingAttribute => {
|
|
69
|
+
// __SetAttribute(listElement, "update-list-info", pendingAttribute);
|
|
70
|
+
// __FlushElementTree(listElement);
|
|
71
|
+
// });
|
|
72
|
+
__SetAttribute(listElement, 'update-list-info', this.__toAttribute());
|
|
73
|
+
__UpdateListCallbacks(
|
|
74
|
+
listElement,
|
|
75
|
+
componentAtIndexFactory(this.list.childNodes),
|
|
76
|
+
enqueueComponentFactory(),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private oldChildNodes: SnapshotInstance[];
|
|
81
|
+
// private oldChildNodesSet: Set<SnapshotInstance>;
|
|
82
|
+
private removeChild = new Set<SnapshotInstance>();
|
|
83
|
+
private insertBefore = new Map<SnapshotInstance, SnapshotInstance[]>(); // insert V before K
|
|
84
|
+
private appendChild = [] as SnapshotInstance[];
|
|
85
|
+
private platformInfoUpdate = new Map<SnapshotInstance, any>();
|
|
86
|
+
|
|
87
|
+
onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance): void {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
if (newNode.__parent) {
|
|
90
|
+
// if (!this.oldChildNodesSet.has(newNode)) {
|
|
91
|
+
// this.__commitAndReset();
|
|
92
|
+
// }
|
|
93
|
+
this.removeChild.add(newNode);
|
|
94
|
+
}
|
|
95
|
+
if (existingNode) {
|
|
96
|
+
// if (!this.oldChildNodesSet.has(existingNode)) {
|
|
97
|
+
// this.__commitAndReset();
|
|
98
|
+
// }
|
|
99
|
+
const newChildren = this.insertBefore.get(existingNode) ?? [];
|
|
100
|
+
newChildren.push(newNode);
|
|
101
|
+
this.insertBefore.set(existingNode, newChildren);
|
|
102
|
+
} else {
|
|
103
|
+
this.appendChild.push(newNode);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
onRemoveChild(child: SnapshotInstance): void {
|
|
108
|
+
// if (!this.oldChildNodesSet.has(child)) {
|
|
109
|
+
// this.__commitAndReset();
|
|
110
|
+
// }
|
|
111
|
+
this.removeChild.add(child);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
onSetAttribute(child: SnapshotInstance, attr: any, _oldAttr: any): void {
|
|
115
|
+
this.platformInfoUpdate.set(child, attr);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private __toAttribute(): UpdateAction {
|
|
119
|
+
const { removeChild, insertBefore, appendChild, platformInfoUpdate } = this;
|
|
120
|
+
|
|
121
|
+
const removals: number[] = [];
|
|
122
|
+
const insertions: { position: number; type: string }[] = [];
|
|
123
|
+
const updates: any[] = [];
|
|
124
|
+
|
|
125
|
+
let j = 0;
|
|
126
|
+
for (let i = 0; i < this.oldChildNodes.length; i++, j++) {
|
|
127
|
+
const child = this.oldChildNodes[i]!;
|
|
128
|
+
if (platformInfoUpdate.has(child)) {
|
|
129
|
+
updates.push({
|
|
130
|
+
...platformInfoUpdate.get(child),
|
|
131
|
+
from: +j,
|
|
132
|
+
to: +j,
|
|
133
|
+
// no flush
|
|
134
|
+
flush: false,
|
|
135
|
+
type: child.type,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (insertBefore.has(child)) {
|
|
139
|
+
const children = insertBefore.get(child)!;
|
|
140
|
+
children.forEach(c => {
|
|
141
|
+
insertions.push({
|
|
142
|
+
position: j,
|
|
143
|
+
type: c.type,
|
|
144
|
+
...c.__listItemPlatformInfo,
|
|
145
|
+
});
|
|
146
|
+
j++;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (removeChild.has(child)) {
|
|
150
|
+
removals.push(i);
|
|
151
|
+
removeChild.delete(child);
|
|
152
|
+
j--;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (let i = 0; i < appendChild.length; i++) {
|
|
156
|
+
const child = appendChild[i]!;
|
|
157
|
+
insertions.push({
|
|
158
|
+
position: j + i,
|
|
159
|
+
type: child.type,
|
|
160
|
+
...child.__listItemPlatformInfo,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
insertions.sort((a, b) => a.position - b.position);
|
|
165
|
+
removals.sort((a, b) => a - b);
|
|
166
|
+
|
|
167
|
+
if (
|
|
168
|
+
SystemInfo.lynxSdkVersion === '2.14'
|
|
169
|
+
|| SystemInfo.lynxSdkVersion === '2.15'
|
|
170
|
+
|| SystemInfo.lynxSdkVersion === '2.16'
|
|
171
|
+
|| SystemInfo.lynxSdkVersion === '2.17'
|
|
172
|
+
|| SystemInfo.lynxSdkVersion === '2.18'
|
|
173
|
+
) {
|
|
174
|
+
const elementIndex = this.list.__snapshot_def.slot[0]![1];
|
|
175
|
+
const listElement = this.list.__elements![elementIndex]!;
|
|
176
|
+
|
|
177
|
+
// `__GetAttributeByName` is avaiable since Lynx 2.14
|
|
178
|
+
if (__GetAttributeByName(listElement, 'custom-list-name') === 'list-container') {
|
|
179
|
+
// `updateAction` must be full (not incremental) when Lynx version <= 2.18 and
|
|
180
|
+
// when `custom-list-name` is `list-container` (avaiable when Lynx version >= 2.14) is true,
|
|
181
|
+
updates.length = 0;
|
|
182
|
+
this.list.childNodes.forEach((child, index) => {
|
|
183
|
+
updates.push({
|
|
184
|
+
...child.__listItemPlatformInfo,
|
|
185
|
+
from: index,
|
|
186
|
+
to: index,
|
|
187
|
+
// no flush
|
|
188
|
+
flush: false,
|
|
189
|
+
type: child.type,
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
insertAction: insertions,
|
|
197
|
+
removeAction: removals,
|
|
198
|
+
updateAction: updates,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
toJSON(): [UpdateAction] {
|
|
203
|
+
// if (this.__pendingAttributes) {
|
|
204
|
+
// return [...this.__pendingAttributes, this.__toAttribute()];
|
|
205
|
+
// } else {
|
|
206
|
+
// return [this.__toAttribute()];
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
return [this.__toAttribute()] as const;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export const __pendingListUpdates = {
|
|
214
|
+
values: {} as Record<number, ListUpdateInfo>,
|
|
215
|
+
clear(): void {
|
|
216
|
+
this.values = {};
|
|
217
|
+
},
|
|
218
|
+
flush(): void {
|
|
219
|
+
Object.values(this.values).forEach(update => {
|
|
220
|
+
update.flush();
|
|
221
|
+
});
|
|
222
|
+
this.clear();
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const gSignMap: Record<number, Map<number, SnapshotInstance>> = {};
|
|
227
|
+
const gRecycleMap: Record<number, Map<string, Map<number, SnapshotInstance>>> = {};
|
|
228
|
+
|
|
229
|
+
export function componentAtIndexFactory(ctx: SnapshotInstance[]): ComponentAtIndexCallback {
|
|
230
|
+
const componentAtIndex = (
|
|
231
|
+
list: FiberElement,
|
|
232
|
+
listID: number,
|
|
233
|
+
cellIndex: number,
|
|
234
|
+
operationID: number,
|
|
235
|
+
enableReuseNotification: boolean,
|
|
236
|
+
) => {
|
|
237
|
+
const signMap = gSignMap[listID];
|
|
238
|
+
const recycleMap = gRecycleMap[listID];
|
|
239
|
+
if (!signMap || !recycleMap) {
|
|
240
|
+
throw new Error('componentAtIndex called on removed list');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const childCtx = ctx[cellIndex];
|
|
244
|
+
if (!childCtx) {
|
|
245
|
+
throw new Error('childCtx not found');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const platformInfo = childCtx.__listItemPlatformInfo || {};
|
|
249
|
+
|
|
250
|
+
const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');
|
|
251
|
+
const recycleSignMap = recycleMap.get(uniqID);
|
|
252
|
+
|
|
253
|
+
if (childCtx.__elements) {
|
|
254
|
+
/**
|
|
255
|
+
* If this situation is encountered, there might be two cases:
|
|
256
|
+
* 1. Reusing with itself
|
|
257
|
+
* In this case, enqueueComponent will be triggered first, followed by componentAtIndex.
|
|
258
|
+
* 2. Moving
|
|
259
|
+
* In this case, the trigger order is uncertain; componentAtIndex might be triggered first, or enqueueComponent might be triggered first.
|
|
260
|
+
*
|
|
261
|
+
* When enqueueComponent is triggered first, there must be an item in the reuse pool with the same sign as here, which can be returned directly.
|
|
262
|
+
* When componentAtIndex is triggered first, a clone needs to be made first, then follow the logic for adding or reusing. The cloned item will enter the reuse pool in the subsequent enqueueComponent.
|
|
263
|
+
*/
|
|
264
|
+
const root = childCtx.__elements[0]!;
|
|
265
|
+
const sign = __GetElementUniqueID(root);
|
|
266
|
+
|
|
267
|
+
if (recycleSignMap?.has(sign)) {
|
|
268
|
+
signMap.set(sign, childCtx);
|
|
269
|
+
recycleSignMap.delete(sign);
|
|
270
|
+
__FlushElementTree(root, { triggerLayout: true, operationID, elementID: sign, listID });
|
|
271
|
+
return sign;
|
|
272
|
+
} else {
|
|
273
|
+
const newCtx = childCtx.takeElements();
|
|
274
|
+
signMap.set(sign, newCtx);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (recycleSignMap && recycleSignMap.size > 0) {
|
|
279
|
+
const [first] = recycleSignMap;
|
|
280
|
+
const [sign, oldCtx] = first!;
|
|
281
|
+
recycleSignMap.delete(sign);
|
|
282
|
+
hydrate(oldCtx, childCtx);
|
|
283
|
+
oldCtx.unRenderElements();
|
|
284
|
+
const root = childCtx.__element_root!;
|
|
285
|
+
if (enableReuseNotification) {
|
|
286
|
+
__FlushElementTree(root, {
|
|
287
|
+
triggerLayout: true,
|
|
288
|
+
operationID,
|
|
289
|
+
elementID: sign,
|
|
290
|
+
listID,
|
|
291
|
+
listReuseNotification: {
|
|
292
|
+
listElement: list,
|
|
293
|
+
itemKey: platformInfo['item-key'],
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
__FlushElementTree(root, {
|
|
298
|
+
triggerLayout: true,
|
|
299
|
+
operationID,
|
|
300
|
+
elementID: sign,
|
|
301
|
+
listID,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
signMap.set(sign, childCtx);
|
|
305
|
+
commitMainThreadPatchUpdate(undefined);
|
|
306
|
+
return sign;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
childCtx.ensureElements();
|
|
310
|
+
const root = childCtx.__element_root!;
|
|
311
|
+
__AppendElement(list, root);
|
|
312
|
+
const sign = __GetElementUniqueID(root);
|
|
313
|
+
__FlushElementTree(root, {
|
|
314
|
+
triggerLayout: true,
|
|
315
|
+
operationID,
|
|
316
|
+
elementID: sign,
|
|
317
|
+
listID,
|
|
318
|
+
});
|
|
319
|
+
signMap.set(sign, childCtx);
|
|
320
|
+
commitMainThreadPatchUpdate(undefined);
|
|
321
|
+
return sign;
|
|
322
|
+
};
|
|
323
|
+
return componentAtIndex;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function enqueueComponentFactory(): EnqueueComponentCallback {
|
|
327
|
+
const enqueueComponent = (_: FiberElement, listID: number, sign: number) => {
|
|
328
|
+
const signMap = gSignMap[listID];
|
|
329
|
+
const recycleMap = gRecycleMap[listID];
|
|
330
|
+
if (!signMap || !recycleMap) {
|
|
331
|
+
throw new Error('enqueueComponent called on removed list');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const childCtx = signMap.get(sign)!;
|
|
335
|
+
if (!childCtx) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const platformInfo = childCtx.__listItemPlatformInfo || {};
|
|
340
|
+
|
|
341
|
+
const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');
|
|
342
|
+
if (!recycleMap.has(uniqID)) {
|
|
343
|
+
recycleMap.set(uniqID, new Map());
|
|
344
|
+
}
|
|
345
|
+
recycleMap.get(uniqID)!.set(sign, childCtx);
|
|
346
|
+
};
|
|
347
|
+
return enqueueComponent;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function snapshotCreateList(
|
|
351
|
+
pageId: number,
|
|
352
|
+
_ctx: SnapshotInstance,
|
|
353
|
+
_expIndex: number,
|
|
354
|
+
): FiberElement {
|
|
355
|
+
const signMap = new Map<number, SnapshotInstance>();
|
|
356
|
+
const recycleMap = new Map<string, Map<number, SnapshotInstance>>();
|
|
357
|
+
const list = __CreateList(
|
|
358
|
+
pageId,
|
|
359
|
+
componentAtIndexFactory([]),
|
|
360
|
+
enqueueComponentFactory(),
|
|
361
|
+
{},
|
|
362
|
+
);
|
|
363
|
+
const listID = __GetElementUniqueID(list);
|
|
364
|
+
gSignMap[listID] = signMap;
|
|
365
|
+
gRecycleMap[listID] = recycleMap;
|
|
366
|
+
return list;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function snapshotDestroyList(si: SnapshotInstance): void {
|
|
370
|
+
const [, elementIndex] = si.__snapshot_def.slot[0]!;
|
|
371
|
+
const list = si.__elements![elementIndex]!;
|
|
372
|
+
const listID = __GetElementUniqueID(list);
|
|
373
|
+
delete gSignMap[listID];
|
|
374
|
+
delete gRecycleMap[listID];
|
|
375
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
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 { __page, setupPage, SnapshotInstance } from '../snapshot.js';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { render as renderToString } from '../renderToOpcodes/index.js';
|
|
7
|
+
import { LifecycleConstant } from '../lifecycleConstant.js';
|
|
8
|
+
import { takeGlobalRefPatchMap } from '../snapshot/ref.js';
|
|
9
|
+
import { isEmptyObject } from '../utils.js';
|
|
10
|
+
import { __root, setRoot } from '../root.js';
|
|
11
|
+
import { reloadMainThread } from '../lifecycle/reload.js';
|
|
12
|
+
import { renderMainThread } from '../lifecycle/render.js';
|
|
13
|
+
import { hydrate } from '../hydrate.js';
|
|
14
|
+
import { markTiming, PerformanceTimingKeys, setPipeline } from './performance.js';
|
|
15
|
+
import { __pendingListUpdates } from '../list.js';
|
|
16
|
+
|
|
17
|
+
function injectCalledByNative(): void {
|
|
18
|
+
const calledByNative: LynxCallByNative = {
|
|
19
|
+
renderPage,
|
|
20
|
+
updatePage,
|
|
21
|
+
updateGlobalProps,
|
|
22
|
+
getPageData: function() {
|
|
23
|
+
return null;
|
|
24
|
+
},
|
|
25
|
+
removeComponents: function(): void {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
Object.assign(globalThis, calledByNative);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function renderPage(data: any): void {
|
|
32
|
+
// reset `jsReady` state
|
|
33
|
+
isJSReady = false;
|
|
34
|
+
jsReadyEventIdSwap = {};
|
|
35
|
+
|
|
36
|
+
lynx.__initData = data || {};
|
|
37
|
+
|
|
38
|
+
setupPage(__CreatePage('0', 0));
|
|
39
|
+
(__root as SnapshotInstance).ensureElements();
|
|
40
|
+
|
|
41
|
+
renderMainThread();
|
|
42
|
+
|
|
43
|
+
// always call this before `__FlushElementTree`
|
|
44
|
+
// (There is an implict `__FlushElementTree` in `renderPage`)
|
|
45
|
+
__pendingListUpdates.flush();
|
|
46
|
+
|
|
47
|
+
if (__FIRST_SCREEN_SYNC_TIMING__ === 'immediately') {
|
|
48
|
+
jsReady();
|
|
49
|
+
} else {
|
|
50
|
+
Object.assign(globalThis, {
|
|
51
|
+
[LifecycleConstant.jsReady]: jsReady,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function updatePage(data: any, options?: UpdatePageOption | undefined): void {
|
|
57
|
+
if (options?.reloadTemplate) {
|
|
58
|
+
reloadMainThread(data, options);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (options?.resetPageData) {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
lynx.__initData = {};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof data == 'object' && !isEmptyObject(data)) {
|
|
68
|
+
lynx.__initData ??= {};
|
|
69
|
+
Object.assign(lynx.__initData, data);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!isJSReady) {
|
|
73
|
+
const oldRoot = __root;
|
|
74
|
+
setRoot(new SnapshotInstance('root'));
|
|
75
|
+
__root.__jsx = oldRoot.__jsx;
|
|
76
|
+
|
|
77
|
+
setPipeline(options?.pipelineOptions);
|
|
78
|
+
markTiming(PerformanceTimingKeys.update_diff_vdom_start);
|
|
79
|
+
{
|
|
80
|
+
__pendingListUpdates.clear();
|
|
81
|
+
|
|
82
|
+
// ignore ref & unref before jsReady
|
|
83
|
+
takeGlobalRefPatchMap();
|
|
84
|
+
renderMainThread();
|
|
85
|
+
// As said by codename `jsReadyEventIdSwap`, this swap will only be used for event remap,
|
|
86
|
+
// because ref & unref cause by previous render will be ignored
|
|
87
|
+
hydrate(
|
|
88
|
+
oldRoot as SnapshotInstance,
|
|
89
|
+
__root as SnapshotInstance,
|
|
90
|
+
{ skipUnRef: true, swap: jsReadyEventIdSwap },
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// always call this before `__FlushElementTree`
|
|
94
|
+
__pendingListUpdates.flush();
|
|
95
|
+
}
|
|
96
|
+
markTiming(PerformanceTimingKeys.update_diff_vdom_end);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (options) {
|
|
100
|
+
__FlushElementTree(__page, options);
|
|
101
|
+
} else {
|
|
102
|
+
__FlushElementTree();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function updateGlobalProps(_data: any, options?: UpdatePageOption | undefined): void {
|
|
107
|
+
if (options) {
|
|
108
|
+
__FlushElementTree(__page, options);
|
|
109
|
+
} else {
|
|
110
|
+
__FlushElementTree();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let isJSReady: boolean;
|
|
115
|
+
let jsReadyEventIdSwap: Record<number, number>;
|
|
116
|
+
function jsReady() {
|
|
117
|
+
__OnLifecycleEvent([
|
|
118
|
+
LifecycleConstant.firstScreen, /* FIRST_SCREEN */
|
|
119
|
+
{
|
|
120
|
+
root: JSON.stringify(__root),
|
|
121
|
+
refPatch: JSON.stringify(takeGlobalRefPatchMap()),
|
|
122
|
+
jsReadyEventIdSwap,
|
|
123
|
+
},
|
|
124
|
+
]);
|
|
125
|
+
isJSReady = true;
|
|
126
|
+
jsReadyEventIdSwap = {};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export { injectCalledByNative };
|
|
@@ -0,0 +1,116 @@
|
|
|
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 { Component } from 'preact';
|
|
5
|
+
|
|
6
|
+
import { PerfSpecificKey, PerformanceTimingKeys, markTimingLegacy } from './performance.js';
|
|
7
|
+
import { globalFlushOptions } from '../lifecycle/patchUpdate.js';
|
|
8
|
+
import { NEXT_STATE } from '../renderToOpcodes/constants.js';
|
|
9
|
+
|
|
10
|
+
if (__JS__) {
|
|
11
|
+
const __Component = Component as any;
|
|
12
|
+
|
|
13
|
+
__Component.prototype._reactAppInstance = lynxCoreInject.tt;
|
|
14
|
+
|
|
15
|
+
__Component.prototype.getNodeRef = function(a: string, b?: boolean) {
|
|
16
|
+
if (!__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__) {
|
|
17
|
+
lynx.reportError(
|
|
18
|
+
new Error(
|
|
19
|
+
'getNodeRef is deprecated and has different behavior in ReactLynx 3.0, please use ref or lynx.createSelectorQuery instead.',
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return lynxCoreInject.tt._reactLynx.ReactComponent.prototype.getNodeRef
|
|
24
|
+
.call(
|
|
25
|
+
{
|
|
26
|
+
_type: '',
|
|
27
|
+
_nativeApp: lynxCoreInject.tt._nativeApp,
|
|
28
|
+
_uiModule: lynxCoreInject.tt._nativeApp.nativeModuleProxy.LynxUIMethodModule,
|
|
29
|
+
_reactAppInstance: lynxCoreInject.tt,
|
|
30
|
+
},
|
|
31
|
+
a,
|
|
32
|
+
b,
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
__Component.prototype.getNodeRefFromRoot = function(a: string) {
|
|
37
|
+
if (!__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__) {
|
|
38
|
+
lynx.reportError(
|
|
39
|
+
new Error(
|
|
40
|
+
'getNodeRefFromRoot is deprecated and has different behavior in ReactLynx 3.0, please use ref or lynx.createSelectorQuery instead.',
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return lynxCoreInject.tt._reactLynx.ReactComponent.prototype
|
|
45
|
+
.getNodeRefFromRoot.call(
|
|
46
|
+
{
|
|
47
|
+
_type: '',
|
|
48
|
+
_nativeApp: lynxCoreInject.tt._nativeApp,
|
|
49
|
+
_uiModule: lynxCoreInject.tt._nativeApp.nativeModuleProxy.LynxUIMethodModule,
|
|
50
|
+
_reactAppInstance: lynxCoreInject.tt,
|
|
51
|
+
},
|
|
52
|
+
a,
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
__Component.prototype.registerModule = function(
|
|
57
|
+
name: string,
|
|
58
|
+
module: object,
|
|
59
|
+
): void {
|
|
60
|
+
this._reactAppInstance.registerModule(name, module);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
__Component.prototype.getJSModule = function<Module = unknown>(
|
|
64
|
+
name: string,
|
|
65
|
+
): Module {
|
|
66
|
+
return this._reactAppInstance.getJSModule(name);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
__Component.prototype.addGlobalEventListener = function(
|
|
70
|
+
eventName: string,
|
|
71
|
+
callback: (...args: unknown[]) => void,
|
|
72
|
+
context?: object,
|
|
73
|
+
): void {
|
|
74
|
+
return this._reactAppInstance.getJSModule('GlobalEventEmitter').addListener(
|
|
75
|
+
eventName,
|
|
76
|
+
callback,
|
|
77
|
+
context,
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
__Component.prototype.getElementById = function(id: string) {
|
|
82
|
+
if (!__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__) {
|
|
83
|
+
lynx.reportError(
|
|
84
|
+
new Error(
|
|
85
|
+
'getElementById on component instance is deprecated and has different behavior in ReactLynx 3.0, please use ref or lynx.getElementById instead.',
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return lynx.getElementById(id);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
__Component.prototype.GlobalEventEmitter = lynxCoreInject.tt.GlobalEventEmitter;
|
|
93
|
+
|
|
94
|
+
__Component.prototype.createSelectorQuery = function(...args: any[]) {
|
|
95
|
+
if (!__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__) {
|
|
96
|
+
lynx.reportError(
|
|
97
|
+
new Error(
|
|
98
|
+
'createSelectorQuery on component instance is deprecated and has different behavior in ReactLynx 3.0, please use ref or lynx.createSelectorQuery instead.',
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return lynx.createSelectorQuery(...args);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const oldSetState = __Component.prototype.setState;
|
|
106
|
+
__Component.prototype.setState = function(state: any, callback: any): void {
|
|
107
|
+
oldSetState.call(this, state, callback);
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
const timingFlag = this[NEXT_STATE][PerfSpecificKey];
|
|
110
|
+
if (timingFlag) {
|
|
111
|
+
globalFlushOptions.__lynx_timing_flag = timingFlag;
|
|
112
|
+
markTimingLegacy(PerformanceTimingKeys.update_set_state_trigger, timingFlag);
|
|
113
|
+
this[NEXT_STATE][PerfSpecificKey] = '';
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { loadLazyBundle } from './lazy-bundle.js';
|
|
5
|
+
|
|
6
|
+
export function loadDynamicJS<T>(url: string): Promise<T> {
|
|
7
|
+
if (__LEPUS__) {
|
|
8
|
+
_ReportError(
|
|
9
|
+
new Error(`A dynamic import (to "${url}") is leaked to Lepus bundle.`),
|
|
10
|
+
{ errorCode: 202 },
|
|
11
|
+
);
|
|
12
|
+
return Promise.reject();
|
|
13
|
+
}
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
lynx.requireModuleAsync(url, (err, data) => {
|
|
17
|
+
if (err) {
|
|
18
|
+
reject(err);
|
|
19
|
+
} else {
|
|
20
|
+
resolve(data);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function __dynamicImport<T>(url: string, options?: any): Promise<T> {
|
|
27
|
+
const t = options?.with?.type;
|
|
28
|
+
if (t === 'component' || t === 'tsx' || t === 'jsx') {
|
|
29
|
+
return loadLazyBundle<any>(url);
|
|
30
|
+
} else {
|
|
31
|
+
return loadDynamicJS(url);
|
|
32
|
+
}
|
|
33
|
+
}
|