@lynx-js/web-worker-runtime 0.10.1 → 0.11.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 +23 -0
- package/dist/backgroundThread/background-apis/createBackgroundLynx.d.ts +12 -2
- package/dist/backgroundThread/background-apis/createBackgroundLynx.js +27 -4
- package/dist/backgroundThread/background-apis/createNativeApp.js +10 -4
- package/dist/backgroundThread/background-apis/createPerformanceApis.d.ts +1 -1
- package/dist/backgroundThread/background-apis/createPerformanceApis.js +6 -0
- package/dist/index.js +1 -1
- package/dist/mainThread/startMainThread.js +11 -6
- package/package.json +6 -6
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerOnLifecycleEventHandler.d.ts +0 -3
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerOnLifecycleEventHandler.js +0 -8
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerOnNativeAppReadyHandler.d.ts +0 -3
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerOnNativeAppReadyHandler.js +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: support mts event handler (1/n) ([#495](https://github.com/lynx-family/lynx-stack/pull/495))
|
|
8
|
+
|
|
9
|
+
now the main-thread:bind handler could be invoked. The params of the handler will be implemented later.
|
|
10
|
+
|
|
11
|
+
- feat: allow multi lynx-view to share bts worker ([#520](https://github.com/lynx-family/lynx-stack/pull/520))
|
|
12
|
+
|
|
13
|
+
Now we allow users to enable so-called "shared-context" feature on the Web Platform.
|
|
14
|
+
|
|
15
|
+
Similar to the same feature for Lynx iOS/Android, this feature let multi lynx cards to share one js context.
|
|
16
|
+
|
|
17
|
+
The `lynx.getSharedData` and `lynx.setSharedData` are also supported in this commit.
|
|
18
|
+
|
|
19
|
+
To enable this feature, set property `lynxGroupId` or attribute `lynx-group-id` before a lynx-view starts rendering. Those card with same context id will share one web worker for the bts scripts.
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`ea42e62`](https://github.com/lynx-family/lynx-stack/commit/ea42e62fbcd5c743132c3e6e7c4851770742d544), [`a0f5ca4`](https://github.com/lynx-family/lynx-stack/commit/a0f5ca4ea0895ccbaa6aa63f449f53a677a1cf73)]:
|
|
22
|
+
- @lynx-js/web-mainthread-apis@0.11.0
|
|
23
|
+
- @lynx-js/web-constants@0.11.0
|
|
24
|
+
- @lynx-js/web-worker-rpc@0.11.0
|
|
25
|
+
|
|
3
26
|
## 0.10.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { dispatchCoreContextEventEndpoint, type Cloneable, type LynxContextEventTarget, type NativeApp } from '@lynx-js/web-constants';
|
|
2
2
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
3
|
export interface CreateLynxConfig {
|
|
4
4
|
globalProps: unknown;
|
|
5
5
|
customSections: Record<string, Cloneable>;
|
|
6
6
|
}
|
|
7
|
+
export declare class LynxCrossThreadContext extends EventTarget implements LynxContextEventTarget {
|
|
8
|
+
private _config;
|
|
9
|
+
constructor(_config: {
|
|
10
|
+
mainThreadRpc: Rpc;
|
|
11
|
+
dispatchEventEndpoint: typeof dispatchCoreContextEventEndpoint;
|
|
12
|
+
});
|
|
13
|
+
postMessage(...args: any[]): void;
|
|
14
|
+
dispatchEvent(event: Event): number;
|
|
15
|
+
__start(): void;
|
|
16
|
+
}
|
|
7
17
|
export declare function createBackgroundLynx(config: CreateLynxConfig, nativeApp: NativeApp, mainThreadRpc: Rpc): {
|
|
8
18
|
__globalProps: unknown;
|
|
9
19
|
getJSModule(_moduleName: string): any;
|
|
10
20
|
getNativeApp(): NativeApp;
|
|
11
|
-
getCoreContext():
|
|
21
|
+
getCoreContext(): LynxCrossThreadContext;
|
|
12
22
|
getCustomSectionSync(key: string): Cloneable;
|
|
13
23
|
getCustomSection: (key: string, callback: (object: Cloneable) => void) => void;
|
|
14
24
|
};
|
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
// Copyright 2023 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 { dispatchCoreContextEventEndpoint, DispatchEventResult, } from '@lynx-js/web-constants';
|
|
4
5
|
import { createGetCustomSection } from './crossThreadHandlers/createGetCustomSection.js';
|
|
6
|
+
export class LynxCrossThreadContext extends EventTarget {
|
|
7
|
+
_config;
|
|
8
|
+
constructor(_config) {
|
|
9
|
+
super();
|
|
10
|
+
this._config = _config;
|
|
11
|
+
}
|
|
12
|
+
postMessage(...args) {
|
|
13
|
+
console.error('[lynx-web] postMessage not implemented, args:', ...args);
|
|
14
|
+
}
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
dispatchEvent(event) {
|
|
17
|
+
super.dispatchEvent(event);
|
|
18
|
+
return DispatchEventResult.CanceledBeforeDispatch;
|
|
19
|
+
}
|
|
20
|
+
__start() {
|
|
21
|
+
const { mainThreadRpc, dispatchEventEndpoint } = this._config;
|
|
22
|
+
mainThreadRpc.registerHandler(dispatchEventEndpoint, (eventType, data) => {
|
|
23
|
+
this.dispatchEvent(new MessageEvent(eventType, { data: data ?? {} }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
5
27
|
export function createBackgroundLynx(config, nativeApp, mainThreadRpc) {
|
|
28
|
+
const coreContext = new LynxCrossThreadContext({
|
|
29
|
+
mainThreadRpc,
|
|
30
|
+
dispatchEventEndpoint: dispatchCoreContextEventEndpoint,
|
|
31
|
+
});
|
|
6
32
|
return {
|
|
7
33
|
__globalProps: config.globalProps,
|
|
8
34
|
getJSModule(_moduleName) {
|
|
@@ -11,10 +37,7 @@ export function createBackgroundLynx(config, nativeApp, mainThreadRpc) {
|
|
|
11
37
|
return nativeApp;
|
|
12
38
|
},
|
|
13
39
|
getCoreContext() {
|
|
14
|
-
return
|
|
15
|
-
addInternalEventListener() { },
|
|
16
|
-
addEventListener() { },
|
|
17
|
-
};
|
|
40
|
+
return coreContext;
|
|
18
41
|
},
|
|
19
42
|
getCustomSectionSync(key) {
|
|
20
43
|
return config.customSections[key];
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, } from '@lynx-js/web-constants';
|
|
2
2
|
import { createInvokeUIMethod } from './crossThreadHandlers/createInvokeUIMethod.js';
|
|
3
|
-
import { registerOnLifecycleEventHandler } from './crossThreadHandlers/registerOnLifecycleEventHandler.js';
|
|
4
3
|
import { registerPublicComponentEventHandler } from './crossThreadHandlers/registerPublicComponentEventHandler.js';
|
|
5
4
|
import { registerGlobalExposureEventHandler } from './crossThreadHandlers/registerGlobalExposureEventHandler.js';
|
|
6
5
|
import { createNativeModules } from './createNativeModules.js';
|
|
7
6
|
import { registerUpdateDataHandler } from './crossThreadHandlers/registerUpdateDataHandler.js';
|
|
8
7
|
import { registerPublishEventHandler } from './crossThreadHandlers/registerPublishEventHandler.js';
|
|
9
8
|
import { createPerformanceApis } from './createPerformanceApis.js';
|
|
10
|
-
import { registerOnNativeAppReadyHandler } from './crossThreadHandlers/registerOnNativeAppReadyHandler.js';
|
|
11
9
|
import { registerSendGlobalEventHandler } from './crossThreadHandlers/registerSendGlobalEvent.js';
|
|
12
10
|
import { createJSObjectDestructionObserver } from './crossThreadHandlers/createJSObjectDestructionObserver.js';
|
|
13
11
|
let nativeAppCount = 0;
|
|
12
|
+
const sharedData = {};
|
|
14
13
|
export async function createNativeApp(config) {
|
|
15
14
|
const { mainThreadRpc, uiThreadRpc, template, nativeModulesMap, timingSystem, } = config;
|
|
16
15
|
const performanceApis = createPerformanceApis(timingSystem);
|
|
@@ -52,6 +51,8 @@ export async function createNativeApp(config) {
|
|
|
52
51
|
const entry = globalThis.module.exports;
|
|
53
52
|
return {
|
|
54
53
|
init: (lynxCoreInject) => {
|
|
54
|
+
lynxCoreInject.tt.lynxCoreInject = lynxCoreInject;
|
|
55
|
+
lynxCoreInject.tt.globalThis ??= lynxCoreInject;
|
|
55
56
|
return entry?.(lynxCoreInject.tt);
|
|
56
57
|
},
|
|
57
58
|
};
|
|
@@ -66,18 +67,23 @@ export async function createNativeApp(config) {
|
|
|
66
67
|
setNativeProps,
|
|
67
68
|
invokeUIMethod: createInvokeUIMethod(uiThreadRpc),
|
|
68
69
|
setCard(tt) {
|
|
69
|
-
registerOnLifecycleEventHandler(mainThreadRpc, tt);
|
|
70
70
|
registerPublicComponentEventHandler(mainThreadRpc, tt);
|
|
71
71
|
registerPublishEventHandler(mainThreadRpc, tt);
|
|
72
72
|
registerGlobalExposureEventHandler(mainThreadRpc, tt);
|
|
73
73
|
registerUpdateDataHandler(uiThreadRpc, tt);
|
|
74
|
-
registerOnNativeAppReadyHandler(uiThreadRpc, tt);
|
|
75
74
|
registerSendGlobalEventHandler(uiThreadRpc, tt);
|
|
76
75
|
timingSystem.registerGlobalEmitter(tt.GlobalEventEmitter);
|
|
76
|
+
tt.lynx.getCoreContext().__start();
|
|
77
77
|
},
|
|
78
78
|
triggerComponentEvent,
|
|
79
79
|
selectComponent,
|
|
80
80
|
createJSObjectDestructionObserver: createJSObjectDestructionObserver(),
|
|
81
|
+
setSharedData(dataKey, dataVal) {
|
|
82
|
+
sharedData[dataKey] = dataVal;
|
|
83
|
+
},
|
|
84
|
+
getSharedData(dataKey) {
|
|
85
|
+
return sharedData[dataKey];
|
|
86
|
+
},
|
|
81
87
|
};
|
|
82
88
|
return nativeApp;
|
|
83
89
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { NativeApp } from '@lynx-js/web-constants';
|
|
2
2
|
import type { TimingSystem } from './createTimingSystem.js';
|
|
3
|
-
export declare function createPerformanceApis(timingSystem: TimingSystem): Pick<NativeApp, 'generatePipelineOptions' | 'onPipelineStart' | 'markPipelineTiming' | 'bindPipelineIdWithTimingFlag'>;
|
|
3
|
+
export declare function createPerformanceApis(timingSystem: TimingSystem): Pick<NativeApp, 'generatePipelineOptions' | 'onPipelineStart' | 'markPipelineTiming' | 'bindPipelineIdWithTimingFlag' | 'profileStart' | 'profileEnd'>;
|
|
@@ -24,6 +24,12 @@ export function createPerformanceApis(timingSystem) {
|
|
|
24
24
|
const timingFlags = timingSystem.pipelineIdToTimingFlags.get(pipelineId);
|
|
25
25
|
timingFlags.push(timingFlag);
|
|
26
26
|
},
|
|
27
|
+
profileStart: () => {
|
|
28
|
+
console.error('NYI: profileStart. This is an issue of lynx-core.');
|
|
29
|
+
},
|
|
30
|
+
profileEnd: () => {
|
|
31
|
+
console.error('NYI: profileEnd. This is an issue of lynx-core.');
|
|
32
|
+
},
|
|
27
33
|
};
|
|
28
34
|
return performanceApis;
|
|
29
35
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2023 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 { BackgroundThreadStartEndpoint,
|
|
4
|
+
import { BackgroundThreadStartEndpoint, mainThreadStartEndpoint, flushElementTreeEndpoint, reportErrorEndpoint, publishEventEndpoint, publicComponentEventEndpoint, postExposureEndpoint, postOffscreenEventEndpoint, switchExposureServiceEndpoint, postTimingFlagsEndpoint, dispatchCoreContextEventEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { MainThreadRuntime, switchExposureService, } from '@lynx-js/web-mainthread-apis';
|
|
7
7
|
import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
|
|
@@ -16,16 +16,16 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
16
16
|
const markTimingInternal = createMarkTimingInternal(backgroundThreadRpc);
|
|
17
17
|
const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
|
|
18
18
|
const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
|
|
19
|
-
const
|
|
19
|
+
const dispatchCoreContextEvent = backgroundThreadRpc.createCall(dispatchCoreContextEventEndpoint);
|
|
20
20
|
const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
|
|
21
21
|
const publicComponentEvent = backgroundThreadRpc.createCall(publicComponentEventEndpoint);
|
|
22
22
|
const postExposure = backgroundThreadRpc.createCall(postExposureEndpoint);
|
|
23
|
-
const mainThreadChunkReady = uiThreadRpc.createCall(mainThreadChunkReadyEndpoint);
|
|
24
23
|
let operations = [];
|
|
25
24
|
const flushElementTree = uiThreadRpc.createCall(flushElementTreeEndpoint);
|
|
26
25
|
const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
|
|
27
26
|
markTimingInternal('lepus_excute_start');
|
|
28
27
|
uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
|
|
28
|
+
let isFp = true;
|
|
29
29
|
const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, } = config;
|
|
30
30
|
const { styleInfo, pageConfig, customSections, cardType, lepusCode } = template;
|
|
31
31
|
markTimingInternal('decode_start');
|
|
@@ -48,8 +48,7 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
48
48
|
lepusCode,
|
|
49
49
|
docu,
|
|
50
50
|
callbacks: {
|
|
51
|
-
mainChunkReady:
|
|
52
|
-
mainThreadChunkReady();
|
|
51
|
+
mainChunkReady: () => {
|
|
53
52
|
markTimingInternal('data_processor_start');
|
|
54
53
|
const initData = runtime.processData
|
|
55
54
|
? runtime.processData(config.initData)
|
|
@@ -75,6 +74,10 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
75
74
|
const pipelineId = options?.pipelineOptions?.pipelineID;
|
|
76
75
|
markTimingInternal('dispatch_start', pipelineId);
|
|
77
76
|
docu.commit();
|
|
77
|
+
if (isFp) {
|
|
78
|
+
isFp = false;
|
|
79
|
+
dispatchCoreContextEvent('__OnNativeAppReady', undefined);
|
|
80
|
+
}
|
|
78
81
|
markTimingInternal('layout_start', pipelineId);
|
|
79
82
|
markTimingInternal('ui_operation_flush_start', pipelineId);
|
|
80
83
|
await flushElementTree(operations);
|
|
@@ -84,7 +87,9 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
84
87
|
postTimingFlags(timingFlags, pipelineId);
|
|
85
88
|
},
|
|
86
89
|
_ReportError: reportError,
|
|
87
|
-
__OnLifecycleEvent
|
|
90
|
+
__OnLifecycleEvent: (data) => {
|
|
91
|
+
dispatchCoreContextEvent('__OnLifecycleEvent', data);
|
|
92
|
+
},
|
|
88
93
|
/**
|
|
89
94
|
* Note :
|
|
90
95
|
* The parameter of lynx.performance.markTiming is (pipelineId:string, timingFlag:string)=>void
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@lynx-js/offscreen-document": "0.0.0",
|
|
26
|
-
"@lynx-js/web-constants": "0.
|
|
27
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
28
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
26
|
+
"@lynx-js/web-constants": "0.11.0",
|
|
27
|
+
"@lynx-js/web-mainthread-apis": "0.11.0",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.11.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@lynx-js/lynx-core": "0.1.
|
|
31
|
+
"@lynx-js/lynx-core": "0.1.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@lynx-js/lynx-core": "0.1.
|
|
34
|
+
"@lynx-js/lynx-core": "0.1.2"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/dist/backgroundThread/background-apis/crossThreadHandlers/registerOnLifecycleEventHandler.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 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 { onLifecycleEventEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
-
export function registerOnLifecycleEventHandler(rpc, tt) {
|
|
6
|
-
rpc.registerHandlerLazy(onLifecycleEventEndpoint, tt, 'OnLifecycleEvent');
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=registerOnLifecycleEventHandler.js.map
|
package/dist/backgroundThread/background-apis/crossThreadHandlers/registerOnNativeAppReadyHandler.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 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 { uiThreadFpReadyEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
-
export function registerOnNativeAppReadyHandler(uiThreadRpc, tt) {
|
|
6
|
-
uiThreadRpc.registerHandlerLazy(uiThreadFpReadyEndpoint, tt, 'onNativeAppReady');
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=registerOnNativeAppReadyHandler.js.map
|