@lynx-js/react 0.109.2 → 0.110.1
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 +33 -0
- package/components/lib/Page.js.map +1 -1
- package/components/src/Page.ts +1 -1
- package/package.json +1 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- package/runtime/lib/backgroundSnapshot.d.ts +2 -1
- package/runtime/lib/backgroundSnapshot.js +66 -42
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/compat/initData.d.ts +7 -5
- package/runtime/lib/compat/initData.js +1 -2
- package/runtime/lib/compat/initData.js.map +1 -1
- package/runtime/lib/compat/lynxComponent.js +10 -12
- package/runtime/lib/compat/lynxComponent.js.map +1 -1
- package/runtime/lib/debug/profile.js +1 -0
- package/runtime/lib/debug/profile.js.map +1 -1
- package/runtime/lib/gesture/processGestureBagkround.d.ts +1 -1
- package/runtime/lib/gesture/processGestureBagkround.js +4 -1
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -1
- package/runtime/lib/gesture/types.js.map +1 -1
- package/runtime/lib/hooks/react.js +3 -3
- package/runtime/lib/hooks/react.js.map +1 -1
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +1 -1
- package/runtime/lib/hydrate.d.ts +1 -1
- package/runtime/lib/hydrate.js +5 -4
- package/runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/internal.d.ts +3 -2
- package/runtime/lib/internal.js +3 -2
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/legacy-react-runtime/index.js +1 -1
- package/runtime/lib/legacy-react-runtime/index.js.map +1 -1
- package/runtime/lib/lifecycle/destroy.js +1 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/lifecycle/event/delayEvents.js +3 -0
- package/runtime/lib/lifecycle/event/delayEvents.js.map +1 -1
- package/runtime/lib/lifecycle/event/delayLifecycleEvents.d.ts +3 -2
- package/runtime/lib/lifecycle/event/delayLifecycleEvents.js +1 -12
- package/runtime/lib/lifecycle/event/delayLifecycleEvents.js.map +1 -1
- package/runtime/lib/lifecycle/event/jsReady.d.ts +1 -1
- package/runtime/lib/lifecycle/event/jsReady.js +3 -2
- package/runtime/lib/lifecycle/event/jsReady.js.map +1 -1
- package/runtime/lib/lifecycle/patch/commit.d.ts +0 -2
- package/runtime/lib/lifecycle/patch/commit.js +8 -36
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/patch/error.d.ts +8 -0
- package/runtime/lib/lifecycle/patch/error.js +47 -0
- package/runtime/lib/lifecycle/patch/error.js.map +1 -0
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js +3 -0
- package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js.map +1 -1
- package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +2 -2
- package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +10 -10
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/lifecycle/patch/updateMainThread.d.ts +0 -1
- package/runtime/lib/lifecycle/patch/updateMainThread.js +7 -14
- package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/lifecycle/ref/delay.d.ts +31 -0
- package/runtime/lib/lifecycle/ref/delay.js +80 -0
- package/runtime/lib/lifecycle/ref/delay.js.map +1 -0
- package/runtime/lib/lifecycle/reload.d.ts +1 -1
- package/runtime/lib/lifecycle/reload.js +8 -5
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/lifecycle/render.js +3 -2
- package/runtime/lib/lifecycle/render.js.map +1 -1
- package/runtime/lib/lifecycleConstant.d.ts +10 -7
- package/runtime/lib/lifecycleConstant.js +8 -8
- package/runtime/lib/lifecycleConstant.js.map +1 -1
- package/runtime/lib/list.d.ts +1 -45
- package/runtime/lib/list.js +31 -206
- package/runtime/lib/list.js.map +1 -1
- package/runtime/lib/listUpdateInfo.d.ts +38 -0
- package/runtime/lib/listUpdateInfo.js +152 -0
- package/runtime/lib/listUpdateInfo.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.js +9 -6
- package/runtime/lib/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/lynx/component.js +7 -0
- package/runtime/lib/lynx/component.js.map +1 -1
- package/runtime/lib/lynx/dynamic-js.d.ts +5 -1
- package/runtime/lib/lynx/dynamic-js.js +1 -0
- package/runtime/lib/lynx/dynamic-js.js.map +1 -1
- package/runtime/lib/lynx/env.d.ts +1 -1
- package/runtime/lib/lynx/env.js +13 -13
- package/runtime/lib/lynx/env.js.map +1 -1
- package/runtime/lib/lynx/lazy-bundle.js +7 -5
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/lynx/performance.js +1 -1
- package/runtime/lib/lynx/performance.js.map +1 -1
- package/runtime/lib/lynx/runWithForce.js +3 -0
- package/runtime/lib/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/lynx/tt.js +12 -33
- package/runtime/lib/lynx/tt.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +1 -1
- package/runtime/lib/lynx-api.js +3 -0
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +6 -6
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/opcodes.js +2 -1
- package/runtime/lib/opcodes.js.map +1 -1
- package/runtime/lib/pendingListUpdates.d.ts +6 -0
- package/runtime/lib/pendingListUpdates.js +16 -0
- package/runtime/lib/pendingListUpdates.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.js +7 -7
- package/runtime/lib/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/dynamicPartType.d.ts +12 -0
- package/runtime/lib/snapshot/dynamicPartType.js +17 -0
- package/runtime/lib/snapshot/dynamicPartType.js.map +1 -0
- package/runtime/lib/snapshot/gesture.js +3 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/list.d.ts +3 -0
- package/runtime/lib/snapshot/list.js +23 -0
- package/runtime/lib/snapshot/list.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +10 -0
- package/runtime/lib/snapshot/platformInfo.js +6 -3
- package/runtime/lib/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/ref.d.ts +17 -9
- package/runtime/lib/snapshot/ref.js +64 -73
- package/runtime/lib/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/spread.d.ts +2 -2
- package/runtime/lib/snapshot/spread.js +12 -12
- package/runtime/lib/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/workletEvent.js +1 -1
- package/runtime/lib/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/workletRef.d.ts +3 -3
- package/runtime/lib/snapshot/workletRef.js +27 -8
- package/runtime/lib/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot.d.ts +9 -18
- package/runtime/lib/snapshot.js +46 -40
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/snapshotInstanceHydrationMap.d.ts +9 -0
- package/runtime/lib/snapshotInstanceHydrationMap.js +16 -0
- package/runtime/lib/snapshotInstanceHydrationMap.js.map +1 -0
- package/runtime/lib/utils.js +1 -1
- package/runtime/lib/utils.js.map +1 -1
- package/runtime/lib/worklet/workletRef.js +1 -2
- package/runtime/lib/worklet/workletRef.js.map +1 -1
- package/runtime/src/backgroundSnapshot.ts +75 -52
- package/runtime/src/compat/initData.ts +10 -9
- package/runtime/src/compat/lynxComponent.ts +12 -13
- package/runtime/src/debug/profile.ts +1 -0
- package/runtime/src/gesture/processGestureBagkround.ts +5 -1
- package/runtime/src/gesture/types.ts +3 -0
- package/runtime/src/hooks/react.ts +3 -3
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +1 -1
- package/runtime/src/hydrate.ts +6 -4
- package/runtime/src/internal.ts +3 -2
- package/runtime/src/legacy-react-runtime/index.ts +1 -1
- package/runtime/src/lifecycle/destroy.ts +1 -0
- package/runtime/src/lifecycle/event/delayEvents.ts +3 -0
- package/runtime/src/lifecycle/event/delayLifecycleEvents.ts +7 -13
- package/runtime/src/lifecycle/event/jsReady.ts +4 -3
- package/runtime/src/lifecycle/patch/commit.ts +10 -41
- package/runtime/src/lifecycle/patch/error.ts +61 -0
- package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +3 -0
- package/runtime/src/lifecycle/patch/snapshotPatch.ts +2 -2
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +28 -28
- package/runtime/src/lifecycle/patch/updateMainThread.ts +7 -16
- package/runtime/src/lifecycle/ref/delay.ts +99 -0
- package/runtime/src/lifecycle/reload.ts +10 -7
- package/runtime/src/lifecycle/render.ts +3 -2
- package/runtime/src/lifecycleConstant.ts +11 -7
- package/runtime/src/list.ts +33 -269
- package/runtime/src/listUpdateInfo.ts +221 -0
- package/runtime/src/lynx/calledByNative.ts +15 -10
- package/runtime/src/lynx/component.ts +9 -0
- package/runtime/src/lynx/dynamic-js.ts +5 -1
- package/runtime/src/lynx/env.ts +17 -17
- package/runtime/src/lynx/lazy-bundle.ts +22 -14
- package/runtime/src/lynx/performance.ts +1 -1
- package/runtime/src/lynx/runWithForce.ts +9 -5
- package/runtime/src/lynx/tt.ts +19 -37
- package/runtime/src/lynx-api.ts +5 -2
- package/runtime/src/lynx.ts +7 -6
- package/runtime/src/opcodes.ts +2 -1
- package/runtime/src/pendingListUpdates.ts +18 -0
- package/runtime/src/renderToOpcodes/index.ts +7 -7
- package/runtime/src/snapshot/dynamicPartType.ts +16 -0
- package/runtime/src/snapshot/gesture.ts +3 -0
- package/runtime/src/snapshot/list.ts +36 -0
- package/runtime/src/snapshot/platformInfo.ts +19 -5
- package/runtime/src/snapshot/ref.ts +78 -87
- package/runtime/src/snapshot/spread.ts +47 -22
- package/runtime/src/snapshot/workletEvent.ts +1 -1
- package/runtime/src/snapshot/workletRef.ts +36 -10
- package/runtime/src/snapshot.ts +62 -51
- package/runtime/src/snapshotInstanceHydrationMap.ts +17 -0
- package/runtime/src/utils.ts +3 -3
- package/runtime/src/worklet/workletRef.ts +1 -2
- package/testing-library/dist/env/vitest.js +8 -6
- package/testing-library/dist/pure.js +4 -3
- package/testing-library/dist/vitest.config.js +7 -7
- package/transform/cjs/main.cjs +4 -0
- package/transform/dist/wasm.cjs +1 -1
- package/worklet-runtime/dist/dev.js +1 -4
- package/worklet-runtime/dist/main.js +0 -3
- package/worklet-runtime/lib/bindings/observers.d.ts +14 -1
- package/worklet-runtime/lib/bindings/observers.js +7 -7
- package/worklet-runtime/lib/bindings/observers.js.map +1 -1
- package/worklet-runtime/lib/hydrate.js +0 -5
- package/worklet-runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/lifecycle/delayUnmount.d.ts +0 -8
- package/runtime/lib/lifecycle/delayUnmount.js +0 -65
- package/runtime/lib/lifecycle/delayUnmount.js.map +0 -1
- package/runtime/src/lifecycle/delayUnmount.ts +0 -77
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NodesRef } from '@lynx-js/types';
|
|
2
|
+
/**
|
|
3
|
+
* A flag to indicate whether UI operations should be delayed.
|
|
4
|
+
* When set to true, UI operations will be queued in the `delayedUiOps` array
|
|
5
|
+
* and executed later when `runDelayedUiOps` is called.
|
|
6
|
+
* This is used before hydration to ensure UI operations are batched
|
|
7
|
+
* and executed at the appropriate time.
|
|
8
|
+
*/
|
|
9
|
+
declare const shouldDelayUiOps: {
|
|
10
|
+
value: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Executes all delayed UI operations.
|
|
14
|
+
*/
|
|
15
|
+
declare function runDelayedUiOps(): void;
|
|
16
|
+
/**
|
|
17
|
+
* A proxy class designed for managing and executing reference-based tasks.
|
|
18
|
+
* It delays the execution of tasks until hydration is complete.
|
|
19
|
+
*/
|
|
20
|
+
declare class RefProxy {
|
|
21
|
+
private readonly refAttr;
|
|
22
|
+
private task;
|
|
23
|
+
constructor(refAttr: [snapshotInstanceId: number, expIndex: number]);
|
|
24
|
+
private setTask;
|
|
25
|
+
invoke(...args: Parameters<NodesRef['invoke']>): RefProxy;
|
|
26
|
+
path(...args: Parameters<NodesRef['path']>): RefProxy;
|
|
27
|
+
fields(...args: Parameters<NodesRef['fields']>): RefProxy;
|
|
28
|
+
setNativeProps(...args: Parameters<NodesRef['setNativeProps']>): RefProxy;
|
|
29
|
+
exec(): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { hydrationMap } from '../../snapshotInstanceHydrationMap.js';
|
|
5
|
+
/**
|
|
6
|
+
* A flag to indicate whether UI operations should be delayed.
|
|
7
|
+
* When set to true, UI operations will be queued in the `delayedUiOps` array
|
|
8
|
+
* and executed later when `runDelayedUiOps` is called.
|
|
9
|
+
* This is used before hydration to ensure UI operations are batched
|
|
10
|
+
* and executed at the appropriate time.
|
|
11
|
+
*/
|
|
12
|
+
const shouldDelayUiOps = { value: true };
|
|
13
|
+
/**
|
|
14
|
+
* An array of functions that will be executed later when `runDelayedUiOps` is called.
|
|
15
|
+
* These functions contain UI operations that need to be delayed.
|
|
16
|
+
*/
|
|
17
|
+
const delayedUiOps = [];
|
|
18
|
+
/**
|
|
19
|
+
* Runs a task either immediately or delays it based on the `shouldDelayUiOps` flag.
|
|
20
|
+
* @param task - The function to execute.
|
|
21
|
+
*/
|
|
22
|
+
function runOrDelay(task) {
|
|
23
|
+
if (shouldDelayUiOps.value) {
|
|
24
|
+
delayedUiOps.push(task);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
task();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Executes all delayed UI operations.
|
|
32
|
+
*/
|
|
33
|
+
function runDelayedUiOps() {
|
|
34
|
+
for (const task of delayedUiOps) {
|
|
35
|
+
task();
|
|
36
|
+
}
|
|
37
|
+
shouldDelayUiOps.value = false;
|
|
38
|
+
delayedUiOps.length = 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A proxy class designed for managing and executing reference-based tasks.
|
|
42
|
+
* It delays the execution of tasks until hydration is complete.
|
|
43
|
+
*/
|
|
44
|
+
class RefProxy {
|
|
45
|
+
refAttr;
|
|
46
|
+
task;
|
|
47
|
+
constructor(refAttr) {
|
|
48
|
+
this.refAttr = refAttr;
|
|
49
|
+
}
|
|
50
|
+
setTask(method, args) {
|
|
51
|
+
this.task = (nodesRef) => {
|
|
52
|
+
return nodesRef[method](...args);
|
|
53
|
+
};
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
invoke(...args) {
|
|
57
|
+
return new RefProxy(this.refAttr).setTask('invoke', args);
|
|
58
|
+
}
|
|
59
|
+
path(...args) {
|
|
60
|
+
return new RefProxy(this.refAttr).setTask('path', args);
|
|
61
|
+
}
|
|
62
|
+
fields(...args) {
|
|
63
|
+
return new RefProxy(this.refAttr).setTask('fields', args);
|
|
64
|
+
}
|
|
65
|
+
setNativeProps(...args) {
|
|
66
|
+
return new RefProxy(this.refAttr).setTask('setNativeProps', args);
|
|
67
|
+
}
|
|
68
|
+
exec() {
|
|
69
|
+
runOrDelay(() => {
|
|
70
|
+
const realRefId = hydrationMap.get(this.refAttr[0]) ?? this.refAttr[0];
|
|
71
|
+
const refSelector = `[react-ref-${realRefId}-${this.refAttr[1]}]`;
|
|
72
|
+
this.task(lynx.createSelectorQuery().select(refSelector)).exec();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
export { RefProxy, runDelayedUiOps, shouldDelayUiOps };
|
|
80
|
+
//# sourceMappingURL=delay.js.map
|
|
@@ -0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AC;IAC5D,CAAC;IAED,IAAI,CAAC,GAAG,IAAkC;QACxC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,GAAG,IAAoC;QAC5C,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,cAAc,CAAC,GAAG,IAA4C;QAC5D,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;IAED,IAAI;QACF,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACvE,MAAM,WAAW,GAAG,cAAc,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;YAClE,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function reloadMainThread(data:
|
|
1
|
+
declare function reloadMainThread(data: unknown, options: UpdatePageOption): void;
|
|
2
2
|
declare function reloadBackground(updateData: Record<string, any>): void;
|
|
3
3
|
export { reloadBackground, reloadMainThread };
|
|
@@ -8,18 +8,19 @@
|
|
|
8
8
|
import { render } from 'preact';
|
|
9
9
|
import { hydrate } from '../hydrate.js';
|
|
10
10
|
import { LifecycleConstant } from '../lifecycleConstant.js';
|
|
11
|
-
import { __pendingListUpdates } from '../
|
|
11
|
+
import { __pendingListUpdates } from '../pendingListUpdates.js';
|
|
12
12
|
import { __root, setRoot } from '../root.js';
|
|
13
|
+
import { destroyBackground } from './destroy.js';
|
|
14
|
+
import { applyRefQueue } from '../snapshot/workletRef.js';
|
|
13
15
|
import { SnapshotInstance, __page, snapshotInstanceManager } from '../snapshot.js';
|
|
14
|
-
import { takeGlobalRefPatchMap } from '../snapshot/ref.js';
|
|
15
16
|
import { isEmptyObject } from '../utils.js';
|
|
16
17
|
import { destroyWorklet } from '../worklet/destroy.js';
|
|
17
|
-
import { destroyBackground } from './destroy.js';
|
|
18
18
|
import { clearJSReadyEventIdSwap, isJSReady } from './event/jsReady.js';
|
|
19
19
|
import { increaseReloadVersion } from './pass.js';
|
|
20
|
+
import { setMainThreadHydrationFinished } from './patch/isMainThreadHydrationFinished.js';
|
|
20
21
|
import { deinitGlobalSnapshotPatch } from './patch/snapshotPatch.js';
|
|
22
|
+
import { shouldDelayUiOps } from './ref/delay.js';
|
|
21
23
|
import { renderMainThread } from './render.js';
|
|
22
|
-
import { setMainThreadHydrationFinished } from './patch/isMainThreadHydrationFinished.js';
|
|
23
24
|
function reloadMainThread(data, options) {
|
|
24
25
|
if (__PROFILE__) {
|
|
25
26
|
console.profile('reloadTemplate');
|
|
@@ -42,12 +43,12 @@ function reloadMainThread(data, options) {
|
|
|
42
43
|
});
|
|
43
44
|
// always call this before `__FlushElementTree`
|
|
44
45
|
__pendingListUpdates.flush();
|
|
46
|
+
applyRefQueue();
|
|
45
47
|
if (isJSReady) {
|
|
46
48
|
__OnLifecycleEvent([
|
|
47
49
|
LifecycleConstant.firstScreen, /* FIRST_SCREEN */
|
|
48
50
|
{
|
|
49
51
|
root: JSON.stringify(__root),
|
|
50
|
-
refPatch: JSON.stringify(takeGlobalRefPatchMap()),
|
|
51
52
|
},
|
|
52
53
|
]);
|
|
53
54
|
}
|
|
@@ -66,6 +67,8 @@ function reloadBackground(updateData) {
|
|
|
66
67
|
increaseReloadVersion();
|
|
67
68
|
// COW when modify `lynx.__initData` to make sure Provider & Consumer works
|
|
68
69
|
lynx.__initData = Object.assign({}, lynx.__initData, updateData);
|
|
70
|
+
shouldDelayUiOps.value = true;
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
69
72
|
render(__root.__jsx, __root);
|
|
70
73
|
if (__PROFILE__) {
|
|
71
74
|
console.profileEnd();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload.js","sourceRoot":"","sources":["../../src/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"reload.js","sourceRoot":"","sources":["../../src/lifecycle/reload.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,uBAAuB,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+CAA+C;IAC/C,oBAAoB,CAAC,KAAK,EAAE,CAAC;IAC7B,aAAa,EAAE,CAAC;IAEhB,IAAI,SAAS,EAAE,CAAC;QACd,kBAAkB,CAAC;YACjB,iBAAiB,CAAC,WAAW,EAAE,kBAAkB;YACjD;gBACE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;aAC7B;SACF,CAAC,CAAC;IACL,CAAC;IAED,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,EAAE,CAAC;IACvB,CAAC;IACD,OAAO;AACT,CAAC;AAED,SAAS,gBAAgB,CAAC,UAA+B;IACvD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,yBAAyB,EAAE,CAAC;IAE5B,iBAAiB,EAAE,CAAC;IAEpB,qBAAqB,EAAE,CAAC;IAExB,2EAA2E;IAC3E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEjE,gBAAgB,CAAC,KAAK,GAAG,IAAI,CAAC;IAC9B,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IAEpC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -12,6 +12,7 @@ function renderMainThread() {
|
|
|
12
12
|
/* v8 ignore start */
|
|
13
13
|
if (process.env['NODE_ENV'] === 'test' && typeof __TESTING_FORCE_RENDER_TO_OPCODE__ !== 'undefined'
|
|
14
14
|
&& !__TESTING_FORCE_RENDER_TO_OPCODE__) {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
15
16
|
render(__root.__jsx, __root);
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
@@ -20,8 +21,7 @@ function renderMainThread() {
|
|
|
20
21
|
if (__PROFILE__) {
|
|
21
22
|
console.profile('renderToString');
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
opcodes = renderToString(__root.__jsx);
|
|
24
|
+
opcodes = renderToString(__root.__jsx, undefined);
|
|
25
25
|
}
|
|
26
26
|
catch (e) {
|
|
27
27
|
lynx.reportError(e);
|
|
@@ -35,6 +35,7 @@ function renderMainThread() {
|
|
|
35
35
|
if (__PROFILE__) {
|
|
36
36
|
console.profile('renderOpcodesInto');
|
|
37
37
|
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
38
39
|
renderOpcodesInto(opcodes, __root);
|
|
39
40
|
if (__ENABLE_SSR__) {
|
|
40
41
|
__root.__opcodes = opcodes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/lifecycle/render.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAE1D;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,SAAS,gBAAgB;IACvB,qBAAqB;IACrB,IACE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,MAAM,IAAI,OAAO,kCAAkC,KAAK,WAAW;WAC5F,CAAC,kCAAkC,EACtC,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAa,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,IAAI,OAAO,CAAC;QACZ,IAAI,C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CAAC;QACD,iEAAiE;QACjE,iBAAiB,CAAC,OAAO,EAAE,MAAa,CAAC,CAAC;QAC1C,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC;QAC7B,CAAC;QACD,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IACD,oBAAoB;AACtB,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export declare const enum LifecycleConstant {
|
|
2
|
+
firstScreen = "rLynxFirstScreen",
|
|
3
|
+
updateFromRoot = "updateFromRoot",
|
|
4
|
+
globalEventFromLepus = "globalEventFromLepus",
|
|
5
|
+
jsReady = "rLynxJSReady",
|
|
6
|
+
patchUpdate = "rLynxChange"
|
|
7
|
+
}
|
|
8
|
+
export interface FirstScreenData {
|
|
9
|
+
root: string;
|
|
10
|
+
jsReadyEventIdSwap: Record<string | number, number>;
|
|
8
11
|
}
|
|
9
12
|
export declare const enum NativeUpdateDataType {
|
|
10
13
|
UPDATE = 0,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
export var LifecycleConstant;
|
|
5
|
+
(function (LifecycleConstant) {
|
|
6
|
+
LifecycleConstant["firstScreen"] = "rLynxFirstScreen";
|
|
7
|
+
LifecycleConstant["updateFromRoot"] = "updateFromRoot";
|
|
8
|
+
LifecycleConstant["globalEventFromLepus"] = "globalEventFromLepus";
|
|
9
|
+
LifecycleConstant["jsReady"] = "rLynxJSReady";
|
|
10
|
+
LifecycleConstant["patchUpdate"] = "rLynxChange";
|
|
11
|
+
})(LifecycleConstant || (LifecycleConstant = {}));
|
|
12
12
|
export var NativeUpdateDataType;
|
|
13
13
|
(function (NativeUpdateDataType) {
|
|
14
14
|
NativeUpdateDataType[NativeUpdateDataType["UPDATE"] = 0] = "UPDATE";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycleConstant.js","sourceRoot":"","sources":["../src/lifecycleConstant.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,
|
|
1
|
+
{"version":3,"file":"lifecycleConstant.js","sourceRoot":"","sources":["../src/lifecycleConstant.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,CAAN,IAAkB,iBAMjB;AAND,WAAkB,iBAAiB;IACjC,qDAAgC,CAAA;IAChC,sDAAiC,CAAA;IACjC,kEAA6C,CAAA;IAC7C,6CAAwB,CAAA;IACxB,gDAA2B,CAAA;AAC7B,CAAC,EANiB,iBAAiB,KAAjB,iBAAiB,QAMlC;AAOD,MAAM,CAAN,IAAkB,oBAGjB;AAHD,WAAkB,oBAAoB;IACpC,mEAAU,CAAA;IACV,iEAAS,CAAA;AACX,CAAC,EAHiB,oBAAoB,KAApB,oBAAoB,QAGrC"}
|
package/runtime/lib/list.d.ts
CHANGED
|
@@ -1,50 +1,6 @@
|
|
|
1
1
|
import type { SnapshotInstance } from './snapshot.js';
|
|
2
|
-
export interface ListUpdateInfo {
|
|
3
|
-
flush(): void;
|
|
4
|
-
onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance): void;
|
|
5
|
-
onRemoveChild(child: SnapshotInstance): void;
|
|
6
|
-
onSetAttribute(child: SnapshotInstance, attr: any, oldAttr: any): void;
|
|
7
|
-
}
|
|
8
|
-
interface InsertAction {
|
|
9
|
-
position: number;
|
|
10
|
-
type: string;
|
|
11
|
-
}
|
|
12
|
-
interface UpdateAction {
|
|
13
|
-
from: number;
|
|
14
|
-
to: number;
|
|
15
|
-
type: string;
|
|
16
|
-
flush: boolean;
|
|
17
|
-
}
|
|
18
|
-
interface ListOperations {
|
|
19
|
-
insertAction: InsertAction[];
|
|
20
|
-
removeAction: number[];
|
|
21
|
-
updateAction: UpdateAction[];
|
|
22
|
-
}
|
|
23
|
-
export declare class ListUpdateInfoRecording implements ListUpdateInfo {
|
|
24
|
-
private list;
|
|
25
|
-
constructor(list: SnapshotInstance);
|
|
26
|
-
flush(): void;
|
|
27
|
-
private oldChildNodes;
|
|
28
|
-
private removeChild;
|
|
29
|
-
private insertBefore;
|
|
30
|
-
private appendChild;
|
|
31
|
-
private platformInfoUpdate;
|
|
32
|
-
onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance): void;
|
|
33
|
-
onRemoveChild(child: SnapshotInstance): void;
|
|
34
|
-
onSetAttribute(child: SnapshotInstance, attr: any, _oldAttr: any): void;
|
|
35
|
-
private __toAttribute;
|
|
36
|
-
toJSON(): [ListOperations];
|
|
37
|
-
}
|
|
38
|
-
export declare const __pendingListUpdates: {
|
|
39
|
-
values: Record<number, ListUpdateInfo>;
|
|
40
|
-
clear(): void;
|
|
41
|
-
flush(): void;
|
|
42
|
-
};
|
|
43
2
|
export declare const gSignMap: Record<number, Map<number, SnapshotInstance>>;
|
|
44
3
|
export declare const gRecycleMap: Record<number, Map<string, Map<number, SnapshotInstance>>>;
|
|
45
4
|
export declare function clearListGlobal(): void;
|
|
46
|
-
export declare function componentAtIndexFactory(ctx: SnapshotInstance[]): [ComponentAtIndexCallback, ComponentAtIndexesCallback];
|
|
5
|
+
export declare function componentAtIndexFactory(ctx: SnapshotInstance[], hydrateFunction: (before: SnapshotInstance, after: SnapshotInstance) => void): [ComponentAtIndexCallback, ComponentAtIndexesCallback];
|
|
47
6
|
export declare function enqueueComponentFactory(): EnqueueComponentCallback;
|
|
48
|
-
export declare function snapshotCreateList(pageId: number, _ctx: SnapshotInstance, _expIndex: number): FiberElement;
|
|
49
|
-
export declare function snapshotDestroyList(si: SnapshotInstance): void;
|
|
50
|
-
export {};
|
package/runtime/lib/list.js
CHANGED
|
@@ -1,187 +1,10 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import {
|
|
5
|
-
import { commitMainThreadPatchUpdate } from './lifecycle/patch/updateMainThread.js';
|
|
6
|
-
// class ListUpdateInfoDiffing implements ListUpdateInfo {
|
|
7
|
-
// private oldChildNodes: SnapshotInstance[];
|
|
8
|
-
// constructor(private list: SnapshotInstance) {
|
|
9
|
-
// this.oldChildNodes = list.childNodes;
|
|
10
|
-
// }
|
|
11
|
-
// flush(): void {
|
|
12
|
-
// Object.defineProperty(SnapshotInstance.prototype, "key", {
|
|
13
|
-
// get: function () {
|
|
14
|
-
// return this.values[0]["item-key"];
|
|
15
|
-
// },
|
|
16
|
-
// });
|
|
17
|
-
// }
|
|
18
|
-
// onInsertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance | undefined): void {}
|
|
19
|
-
// onRemoveChild(child: SnapshotInstance): void {}
|
|
20
|
-
// onSetAttribute(child: SnapshotInstance, attr: any): void {
|
|
21
|
-
// throw new Error("Method not implemented.");
|
|
22
|
-
// }
|
|
23
|
-
// }
|
|
24
|
-
export class ListUpdateInfoRecording {
|
|
25
|
-
list;
|
|
26
|
-
constructor(list) {
|
|
27
|
-
this.list = list;
|
|
28
|
-
this.oldChildNodes = list.childNodes;
|
|
29
|
-
// this.oldChildNodesSet = new Set(this.oldChildNodes);
|
|
30
|
-
}
|
|
31
|
-
// private __commitAndReset() {
|
|
32
|
-
// (this.__pendingAttributes ??= []).push(this.__toAttribute());
|
|
33
|
-
// this.oldChildNodes = this.list.childNodes;
|
|
34
|
-
// this.oldChildNodesSet = new Set(this.oldChildNodes);
|
|
35
|
-
// this.removeChild1.clear();
|
|
36
|
-
// this.removeChild2.clear();
|
|
37
|
-
// this.insertBefore.clear();
|
|
38
|
-
// this.appendChild.length = 0;
|
|
39
|
-
// this.platformInfoUpdate.clear();
|
|
40
|
-
// }
|
|
41
|
-
flush() {
|
|
42
|
-
const elementIndex = this.list.__snapshot_def.slot[0][1];
|
|
43
|
-
const listElement = this.list.__elements[elementIndex];
|
|
44
|
-
// this.__pendingAttributes?.forEach(pendingAttribute => {
|
|
45
|
-
// __SetAttribute(listElement, "update-list-info", pendingAttribute);
|
|
46
|
-
// __FlushElementTree(listElement);
|
|
47
|
-
// });
|
|
48
|
-
__SetAttribute(listElement, 'update-list-info', this.__toAttribute());
|
|
49
|
-
const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory(this.list.childNodes);
|
|
50
|
-
__UpdateListCallbacks(listElement, componentAtIndex, enqueueComponentFactory(), componentAtIndexes);
|
|
51
|
-
}
|
|
52
|
-
oldChildNodes;
|
|
53
|
-
// private oldChildNodesSet: Set<SnapshotInstance>;
|
|
54
|
-
removeChild = new Set();
|
|
55
|
-
insertBefore = new Map(); // insert V before K
|
|
56
|
-
appendChild = [];
|
|
57
|
-
platformInfoUpdate = new Map();
|
|
58
|
-
onInsertBefore(newNode, existingNode) {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
if (newNode.__parent) {
|
|
61
|
-
// if (!this.oldChildNodesSet.has(newNode)) {
|
|
62
|
-
// this.__commitAndReset();
|
|
63
|
-
// }
|
|
64
|
-
this.removeChild.add(newNode);
|
|
65
|
-
}
|
|
66
|
-
if (existingNode) {
|
|
67
|
-
// if (!this.oldChildNodesSet.has(existingNode)) {
|
|
68
|
-
// this.__commitAndReset();
|
|
69
|
-
// }
|
|
70
|
-
const newChildren = this.insertBefore.get(existingNode) ?? [];
|
|
71
|
-
newChildren.push(newNode);
|
|
72
|
-
this.insertBefore.set(existingNode, newChildren);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.appendChild.push(newNode);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
onRemoveChild(child) {
|
|
79
|
-
// if (!this.oldChildNodesSet.has(child)) {
|
|
80
|
-
// this.__commitAndReset();
|
|
81
|
-
// }
|
|
82
|
-
this.removeChild.add(child);
|
|
83
|
-
}
|
|
84
|
-
onSetAttribute(child, attr, _oldAttr) {
|
|
85
|
-
this.platformInfoUpdate.set(child, attr);
|
|
86
|
-
}
|
|
87
|
-
__toAttribute() {
|
|
88
|
-
const { removeChild, insertBefore, appendChild, platformInfoUpdate } = this;
|
|
89
|
-
const removals = [];
|
|
90
|
-
const insertions = [];
|
|
91
|
-
const updates = [];
|
|
92
|
-
let j = 0;
|
|
93
|
-
for (let i = 0; i < this.oldChildNodes.length; i++, j++) {
|
|
94
|
-
const child = this.oldChildNodes[i];
|
|
95
|
-
if (platformInfoUpdate.has(child)) {
|
|
96
|
-
updates.push({
|
|
97
|
-
...platformInfoUpdate.get(child),
|
|
98
|
-
from: +j,
|
|
99
|
-
to: +j,
|
|
100
|
-
// no flush
|
|
101
|
-
flush: false,
|
|
102
|
-
type: child.type,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (insertBefore.has(child)) {
|
|
106
|
-
const children = insertBefore.get(child);
|
|
107
|
-
children.forEach(c => {
|
|
108
|
-
insertions.push({
|
|
109
|
-
position: j,
|
|
110
|
-
type: c.type,
|
|
111
|
-
...c.__listItemPlatformInfo,
|
|
112
|
-
});
|
|
113
|
-
j++;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (removeChild.has(child)) {
|
|
117
|
-
removals.push(i);
|
|
118
|
-
removeChild.delete(child);
|
|
119
|
-
j--;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (let i = 0; i < appendChild.length; i++) {
|
|
123
|
-
const child = appendChild[i];
|
|
124
|
-
insertions.push({
|
|
125
|
-
position: j + i,
|
|
126
|
-
type: child.type,
|
|
127
|
-
...child.__listItemPlatformInfo,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
insertions.sort((a, b) => a.position - b.position);
|
|
131
|
-
removals.sort((a, b) => a - b);
|
|
132
|
-
if (SystemInfo.lynxSdkVersion === '2.14'
|
|
133
|
-
|| SystemInfo.lynxSdkVersion === '2.15'
|
|
134
|
-
|| SystemInfo.lynxSdkVersion === '2.16'
|
|
135
|
-
|| SystemInfo.lynxSdkVersion === '2.17'
|
|
136
|
-
|| SystemInfo.lynxSdkVersion === '2.18') {
|
|
137
|
-
const elementIndex = this.list.__snapshot_def.slot[0][1];
|
|
138
|
-
const listElement = this.list.__elements[elementIndex];
|
|
139
|
-
// `__GetAttributeByName` is available since Lynx 2.14
|
|
140
|
-
if (__GetAttributeByName(listElement, 'custom-list-name') === 'list-container') {
|
|
141
|
-
// `updateAction` must be full (not incremental) when Lynx version <= 2.18 and
|
|
142
|
-
// when `custom-list-name` is `list-container` (available when Lynx version >= 2.14) is true,
|
|
143
|
-
updates.length = 0;
|
|
144
|
-
this.list.childNodes.forEach((child, index) => {
|
|
145
|
-
updates.push({
|
|
146
|
-
...child.__listItemPlatformInfo,
|
|
147
|
-
from: index,
|
|
148
|
-
to: index,
|
|
149
|
-
// no flush
|
|
150
|
-
flush: false,
|
|
151
|
-
type: child.type,
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
insertAction: insertions,
|
|
158
|
-
removeAction: removals,
|
|
159
|
-
updateAction: updates,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
toJSON() {
|
|
163
|
-
// if (this.__pendingAttributes) {
|
|
164
|
-
// return [...this.__pendingAttributes, this.__toAttribute()];
|
|
165
|
-
// } else {
|
|
166
|
-
// return [this.__toAttribute()];
|
|
167
|
-
// }
|
|
168
|
-
return [this.__toAttribute()];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
export const __pendingListUpdates = {
|
|
172
|
-
values: {},
|
|
173
|
-
clear() {
|
|
174
|
-
this.values = {};
|
|
175
|
-
},
|
|
176
|
-
flush() {
|
|
177
|
-
Object.values(this.values).forEach(update => {
|
|
178
|
-
update.flush();
|
|
179
|
-
});
|
|
180
|
-
this.clear();
|
|
181
|
-
},
|
|
182
|
-
};
|
|
4
|
+
import { applyRefQueue } from './snapshot/workletRef.js';
|
|
183
5
|
export const gSignMap = {};
|
|
184
6
|
export const gRecycleMap = {};
|
|
7
|
+
const gParentWeakMap = new WeakMap();
|
|
185
8
|
export function clearListGlobal() {
|
|
186
9
|
for (const key in gSignMap) {
|
|
187
10
|
delete gSignMap[key];
|
|
@@ -190,7 +13,24 @@ export function clearListGlobal() {
|
|
|
190
13
|
delete gRecycleMap[key];
|
|
191
14
|
}
|
|
192
15
|
}
|
|
193
|
-
export function componentAtIndexFactory(ctx) {
|
|
16
|
+
export function componentAtIndexFactory(ctx, hydrateFunction) {
|
|
17
|
+
// A hack workaround to ensure childCtx has no direct reference through `__parent` to list,
|
|
18
|
+
// to avoid memory leak.
|
|
19
|
+
// TODO(hzy): make `__parent` a WeakRef or `#__parent` in the future.
|
|
20
|
+
ctx.forEach((childCtx) => {
|
|
21
|
+
if (gParentWeakMap.has(childCtx)) {
|
|
22
|
+
// do it only once
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
gParentWeakMap.set(childCtx, childCtx.parentNode);
|
|
26
|
+
Object.defineProperty(childCtx, '__parent', {
|
|
27
|
+
get: () => gParentWeakMap.get(childCtx),
|
|
28
|
+
set: (value) => {
|
|
29
|
+
gParentWeakMap.set(childCtx, value);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
194
34
|
const componentAtIndex = (list, listID, cellIndex, operationID, enableReuseNotification, enableBatchRender = false, asyncFlush = false) => {
|
|
195
35
|
const signMap = gSignMap[listID];
|
|
196
36
|
const recycleMap = gRecycleMap[listID];
|
|
@@ -201,7 +41,7 @@ export function componentAtIndexFactory(ctx) {
|
|
|
201
41
|
if (!childCtx) {
|
|
202
42
|
throw new Error('childCtx not found');
|
|
203
43
|
}
|
|
204
|
-
const platformInfo = childCtx.__listItemPlatformInfo
|
|
44
|
+
const platformInfo = childCtx.__listItemPlatformInfo ?? {};
|
|
205
45
|
const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');
|
|
206
46
|
const recycleSignMap = recycleMap.get(uniqID);
|
|
207
47
|
if (childCtx.__elements) {
|
|
@@ -226,10 +66,8 @@ export function componentAtIndexFactory(ctx) {
|
|
|
226
66
|
else if (enableBatchRender && asyncFlush) {
|
|
227
67
|
__FlushElementTree(root, { asyncFlush: true });
|
|
228
68
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// in this case, no need to invoke __FlushElementTree because in the end of componentAtIndexes(), the list will invoke __FlushElementTree.
|
|
232
|
-
}
|
|
69
|
+
// enableBatchRender == true && asyncFlush == false
|
|
70
|
+
// in this case, no need to invoke __FlushElementTree because in the end of componentAtIndexes(), the list will invoke __FlushElementTree.
|
|
233
71
|
return sign;
|
|
234
72
|
}
|
|
235
73
|
else {
|
|
@@ -241,9 +79,13 @@ export function componentAtIndexFactory(ctx) {
|
|
|
241
79
|
const [first] = recycleSignMap;
|
|
242
80
|
const [sign, oldCtx] = first;
|
|
243
81
|
recycleSignMap.delete(sign);
|
|
244
|
-
|
|
82
|
+
hydrateFunction(oldCtx, childCtx);
|
|
245
83
|
oldCtx.unRenderElements();
|
|
84
|
+
if (!oldCtx.__id) {
|
|
85
|
+
oldCtx.tearDown();
|
|
86
|
+
}
|
|
246
87
|
const root = childCtx.__element_root;
|
|
88
|
+
applyRefQueue();
|
|
247
89
|
if (!enableBatchRender) {
|
|
248
90
|
const flushOptions = {
|
|
249
91
|
triggerLayout: true,
|
|
@@ -272,13 +114,13 @@ export function componentAtIndexFactory(ctx) {
|
|
|
272
114
|
__FlushElementTree(root, flushOptions);
|
|
273
115
|
}
|
|
274
116
|
signMap.set(sign, childCtx);
|
|
275
|
-
commitMainThreadPatchUpdate(undefined);
|
|
276
117
|
return sign;
|
|
277
118
|
}
|
|
278
119
|
childCtx.ensureElements();
|
|
279
120
|
const root = childCtx.__element_root;
|
|
280
121
|
__AppendElement(list, root);
|
|
281
122
|
const sign = __GetElementUniqueID(root);
|
|
123
|
+
applyRefQueue();
|
|
282
124
|
if (!enableBatchRender) {
|
|
283
125
|
__FlushElementTree(root, {
|
|
284
126
|
triggerLayout: true,
|
|
@@ -293,7 +135,6 @@ export function componentAtIndexFactory(ctx) {
|
|
|
293
135
|
});
|
|
294
136
|
}
|
|
295
137
|
signMap.set(sign, childCtx);
|
|
296
|
-
commitMainThreadPatchUpdate(undefined);
|
|
297
138
|
return sign;
|
|
298
139
|
};
|
|
299
140
|
const componentAtIndexes = (list, listID, cellIndexes, operationIDs, enableReuseNotification, asyncFlush) => {
|
|
@@ -311,6 +152,7 @@ export function componentAtIndexFactory(ctx) {
|
|
|
311
152
|
return [componentAtIndex, componentAtIndexes];
|
|
312
153
|
}
|
|
313
154
|
export function enqueueComponentFactory() {
|
|
155
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
314
156
|
const enqueueComponent = (_, listID, sign) => {
|
|
315
157
|
const signMap = gSignMap[listID];
|
|
316
158
|
const recycleMap = gRecycleMap[listID];
|
|
@@ -321,7 +163,7 @@ export function enqueueComponentFactory() {
|
|
|
321
163
|
if (!childCtx) {
|
|
322
164
|
return;
|
|
323
165
|
}
|
|
324
|
-
const platformInfo = childCtx.__listItemPlatformInfo
|
|
166
|
+
const platformInfo = childCtx.__listItemPlatformInfo ?? {};
|
|
325
167
|
const uniqID = childCtx.type + (platformInfo['reuse-identifier'] ?? '');
|
|
326
168
|
if (!recycleMap.has(uniqID)) {
|
|
327
169
|
recycleMap.set(uniqID, new Map());
|
|
@@ -330,21 +172,4 @@ export function enqueueComponentFactory() {
|
|
|
330
172
|
};
|
|
331
173
|
return enqueueComponent;
|
|
332
174
|
}
|
|
333
|
-
export function snapshotCreateList(pageId, _ctx, _expIndex) {
|
|
334
|
-
const signMap = new Map();
|
|
335
|
-
const recycleMap = new Map();
|
|
336
|
-
const [componentAtIndex, componentAtIndexes] = componentAtIndexFactory([]);
|
|
337
|
-
const list = __CreateList(pageId, componentAtIndex, enqueueComponentFactory(), {}, componentAtIndexes);
|
|
338
|
-
const listID = __GetElementUniqueID(list);
|
|
339
|
-
gSignMap[listID] = signMap;
|
|
340
|
-
gRecycleMap[listID] = recycleMap;
|
|
341
|
-
return list;
|
|
342
|
-
}
|
|
343
|
-
export function snapshotDestroyList(si) {
|
|
344
|
-
const [, elementIndex] = si.__snapshot_def.slot[0];
|
|
345
|
-
const list = si.__elements[elementIndex];
|
|
346
|
-
const listID = __GetElementUniqueID(list);
|
|
347
|
-
delete gSignMap[listID];
|
|
348
|
-
delete gRecycleMap[listID];
|
|
349
|
-
}
|
|
350
175
|
//# sourceMappingURL=list.js.map
|