@lynx-js/web-worker-runtime 0.13.5 → 0.14.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 +56 -0
- package/dist/backgroundThread/background-apis/createBackgroundLynx.d.ts +5 -8
- package/dist/backgroundThread/background-apis/createBackgroundLynx.js +1 -0
- package/dist/backgroundThread/background-apis/createNativeApp.d.ts +2 -5
- package/dist/backgroundThread/background-apis/createNativeApp.js +5 -1
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerUpdateI18nResource.d.ts +4 -0
- package/dist/backgroundThread/background-apis/crossThreadHandlers/registerUpdateI18nResource.js +18 -0
- package/dist/backgroundThread/background-apis/startBackgroundThread.js +5 -1
- package/dist/mainThread/startMainThread.js +15 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: The parameter config of loadCard needs to add updateData, otherwise some event binding will fail when enableJSDataProcessor is turned on. ([#1077](https://github.com/lynx-family/lynx-stack/pull/1077))
|
|
8
|
+
|
|
9
|
+
- feat: add `_I18nResourceTranslation` api in mts && `init-i18n-resources` attr, `i18nResourceMissed` event of lynx-view. ([#1065](https://github.com/lynx-family/lynx-stack/pull/1065))
|
|
10
|
+
|
|
11
|
+
`init-i18n-resource` is the complete set of i18nResources that need to be maintained on the container side. Note: You need to pass this value when lynx-view is initialized.
|
|
12
|
+
|
|
13
|
+
You can use `_I18nResourceTranslation` in MTS to get the corresponding i18nResource from `init-i18n-resources`. If it is undefined, the `i18nResourceMissed` event will be dispatched.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// ui thread
|
|
17
|
+
lynxView.initI18nResources = [
|
|
18
|
+
{
|
|
19
|
+
options: {
|
|
20
|
+
locale: 'en',
|
|
21
|
+
channel: '1',
|
|
22
|
+
fallback_url: '',
|
|
23
|
+
},
|
|
24
|
+
resource: {
|
|
25
|
+
hello: 'hello',
|
|
26
|
+
lynx: 'lynx web platform1',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
lynxView.addEventListener('i18nResourceMissed', (e) => {
|
|
31
|
+
console.log(e);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// mts
|
|
35
|
+
_I18nResourceTranslation({
|
|
36
|
+
locale: 'en',
|
|
37
|
+
channel: '1',
|
|
38
|
+
fallback_url: '',
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- feat: supports `lynx.getI18nResource()` and `onI18nResourceReady` event in bts. ([#1088](https://github.com/lynx-family/lynx-stack/pull/1088))
|
|
43
|
+
|
|
44
|
+
- `lynx.getI18nResource()` can be used to get i18nResource in bts, it has two data sources:
|
|
45
|
+
- the result of `_I18nResourceTranslation()`
|
|
46
|
+
- lynx-view `updateI18nResources(data: InitI18nResources, options: I18nResourceTranslationOptions)`, it will be matched to the correct i8nResource as a result of `lynx.getI18nResource()`
|
|
47
|
+
- `onI18nResourceReady` event can be used to listen `_I18nResourceTranslation` and lynx-view `updateI18nResources` execution.
|
|
48
|
+
|
|
49
|
+
- feat: add `updateI18nResources` method of lynx-view. ([#1085](https://github.com/lynx-family/lynx-stack/pull/1085))
|
|
50
|
+
|
|
51
|
+
Now you can use `updateI18nResources` to update i18nResources, and then use \_I18nResourceTranslation() to get the updated result.
|
|
52
|
+
|
|
53
|
+
- Updated dependencies [[`25a04c9`](https://github.com/lynx-family/lynx-stack/commit/25a04c9e59f4b893227bdead74f2de69f6615cdb), [`0dbb8b1`](https://github.com/lynx-family/lynx-stack/commit/0dbb8b1f580d0700e2b67b92018a7a00d1494837), [`f99de1e`](https://github.com/lynx-family/lynx-stack/commit/f99de1ef60cc5a11eae4fd0acc70a490787d36c9), [`873a285`](https://github.com/lynx-family/lynx-stack/commit/873a2852fa3df9e32c48a6504160bb243540c7b9), [`afacb2c`](https://github.com/lynx-family/lynx-stack/commit/afacb2cbea7feca46c553651000625d0845b2b00), [`1861cbe`](https://github.com/lynx-family/lynx-stack/commit/1861cbead4b373e0511214999b0e100b6285fa9a)]:
|
|
54
|
+
- @lynx-js/web-mainthread-apis@0.14.0
|
|
55
|
+
- @lynx-js/web-constants@0.14.0
|
|
56
|
+
- @lynx-js/offscreen-document@0.1.2
|
|
57
|
+
- @lynx-js/web-worker-rpc@0.14.0
|
|
58
|
+
|
|
3
59
|
## 0.13.5
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { LynxCrossThreadContext, type
|
|
1
|
+
import { LynxCrossThreadContext, type BackMainThreadContextConfig, type NativeApp } from '@lynx-js/web-constants';
|
|
2
2
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
-
export
|
|
4
|
-
globalProps: unknown;
|
|
5
|
-
customSections: Record<string, Cloneable>;
|
|
6
|
-
}
|
|
7
|
-
export declare function createBackgroundLynx(config: CreateLynxConfig, nativeApp: NativeApp, mainThreadRpc: Rpc, uiThreadRpc: Rpc): {
|
|
3
|
+
export declare function createBackgroundLynx(config: BackMainThreadContextConfig, nativeApp: NativeApp, mainThreadRpc: Rpc, uiThreadRpc: Rpc): {
|
|
8
4
|
__globalProps: unknown;
|
|
9
5
|
getJSModule(_moduleName: string): any;
|
|
10
6
|
getNativeApp(): NativeApp;
|
|
11
7
|
getCoreContext(): LynxCrossThreadContext;
|
|
12
|
-
getCustomSectionSync(key: string): Cloneable;
|
|
13
|
-
getCustomSection: (key: string, callback: (object: Cloneable) => void) => void;
|
|
8
|
+
getCustomSectionSync(key: string): import("@lynx-js/web-constants").Cloneable;
|
|
9
|
+
getCustomSection: (key: string, callback: (object: import("@lynx-js/web-constants").Cloneable) => void) => void;
|
|
14
10
|
queueMicrotask: (callback: () => void) => void;
|
|
15
11
|
createElement(_: string, id: string): {
|
|
16
12
|
animate(operation: import("@lynx-js/web-constants").AnimationOperation, id: string, keyframes?: Record<string, any>[], timingOptions?: Record<string, any>): void;
|
|
17
13
|
};
|
|
14
|
+
getI18nResource: () => import("@lynx-js/web-constants").Cloneable;
|
|
18
15
|
};
|
|
@@ -30,6 +30,7 @@ export function createBackgroundLynx(config, nativeApp, mainThreadRpc, uiThreadR
|
|
|
30
30
|
createElement(_, id) {
|
|
31
31
|
return createElement(id, uiThreadRpc);
|
|
32
32
|
},
|
|
33
|
+
getI18nResource: () => nativeApp.i18nResource.data,
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
//# sourceMappingURL=createBackgroundLynx.js.map
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
import { type
|
|
2
|
+
import { type NativeApp, type BackMainThreadContextConfig } from '@lynx-js/web-constants';
|
|
3
3
|
import type { TimingSystem } from './createTimingSystem.js';
|
|
4
4
|
export declare function createNativeApp(config: {
|
|
5
|
-
template: LynxTemplate;
|
|
6
5
|
uiThreadRpc: Rpc;
|
|
7
6
|
mainThreadRpc: Rpc;
|
|
8
|
-
nativeModulesMap: NativeModulesMap;
|
|
9
7
|
timingSystem: TimingSystem;
|
|
10
|
-
|
|
11
|
-
}): Promise<NativeApp>;
|
|
8
|
+
} & BackMainThreadContextConfig): Promise<NativeApp>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, systemInfo, } from '@lynx-js/web-constants';
|
|
1
|
+
import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, systemInfo, I18nResource, } from '@lynx-js/web-constants';
|
|
2
2
|
import { createInvokeUIMethod } from './crossThreadHandlers/createInvokeUIMethod.js';
|
|
3
3
|
import { registerPublicComponentEventHandler } from './crossThreadHandlers/registerPublicComponentEventHandler.js';
|
|
4
4
|
import { registerGlobalExposureEventHandler } from './crossThreadHandlers/registerGlobalExposureEventHandler.js';
|
|
@@ -9,6 +9,7 @@ import { createPerformanceApis } from './createPerformanceApis.js';
|
|
|
9
9
|
import { registerSendGlobalEventHandler } from './crossThreadHandlers/registerSendGlobalEvent.js';
|
|
10
10
|
import { createJSObjectDestructionObserver } from './crossThreadHandlers/createJSObjectDestructionObserver.js';
|
|
11
11
|
import { registerUpdateGlobalPropsHandler } from './crossThreadHandlers/registerUpdateGlobalPropsHandler.js';
|
|
12
|
+
import { registerUpdateI18nResource } from './crossThreadHandlers/registerUpdateI18nResource.js';
|
|
12
13
|
let nativeAppCount = 0;
|
|
13
14
|
const sharedData = {};
|
|
14
15
|
export async function createNativeApp(config) {
|
|
@@ -45,6 +46,7 @@ export async function createNativeApp(config) {
|
|
|
45
46
|
},
|
|
46
47
|
};
|
|
47
48
|
};
|
|
49
|
+
const i18nResource = new I18nResource();
|
|
48
50
|
const nativeApp = {
|
|
49
51
|
id: (nativeAppCount++).toString(),
|
|
50
52
|
...performanceApis,
|
|
@@ -86,6 +88,7 @@ export async function createNativeApp(config) {
|
|
|
86
88
|
registerUpdateDataHandler(uiThreadRpc, tt);
|
|
87
89
|
registerSendGlobalEventHandler(uiThreadRpc, tt);
|
|
88
90
|
registerUpdateGlobalPropsHandler(uiThreadRpc, tt);
|
|
91
|
+
registerUpdateI18nResource(uiThreadRpc, mainThreadRpc, i18nResource, tt);
|
|
89
92
|
timingSystem.registerGlobalEmitter(tt.GlobalEventEmitter);
|
|
90
93
|
tt.lynx.getCoreContext().__start();
|
|
91
94
|
},
|
|
@@ -98,6 +101,7 @@ export async function createNativeApp(config) {
|
|
|
98
101
|
getSharedData(dataKey) {
|
|
99
102
|
return sharedData[dataKey];
|
|
100
103
|
},
|
|
104
|
+
i18nResource,
|
|
101
105
|
};
|
|
102
106
|
return nativeApp;
|
|
103
107
|
}
|
package/dist/backgroundThread/background-apis/crossThreadHandlers/registerUpdateI18nResource.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type NativeTTObject } from '@lynx-js/web-constants';
|
|
2
|
+
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
+
import { I18nResource } from '@lynx-js/web-constants';
|
|
4
|
+
export declare function registerUpdateI18nResource(uiThreadRpc: Rpc, mainThreadRpc: Rpc, i18nResource: I18nResource, tt: NativeTTObject): void;
|
package/dist/backgroundThread/background-apis/crossThreadHandlers/registerUpdateI18nResource.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 { dispatchI18nResourceEndpoint, updateI18nResourceEndpoint, } from '@lynx-js/web-constants';
|
|
5
|
+
import { I18nResource } from '@lynx-js/web-constants';
|
|
6
|
+
export function registerUpdateI18nResource(uiThreadRpc, mainThreadRpc, i18nResource, tt) {
|
|
7
|
+
// updateI18nResourceEndpoint from ui thread
|
|
8
|
+
uiThreadRpc.registerHandler(updateI18nResourceEndpoint, (data) => {
|
|
9
|
+
i18nResource.setData(data);
|
|
10
|
+
tt.GlobalEventEmitter.emit('onI18nResourceReady', []);
|
|
11
|
+
});
|
|
12
|
+
// dispatchI18nResource from mts
|
|
13
|
+
mainThreadRpc.registerHandler(dispatchI18nResourceEndpoint, (data) => {
|
|
14
|
+
i18nResource.setData(data);
|
|
15
|
+
tt.GlobalEventEmitter.emit('onI18nResourceReady', []);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=registerUpdateI18nResource.js.map
|
|
@@ -27,7 +27,11 @@ export function startBackgroundThread(uiThreadPort, mainThreadPort) {
|
|
|
27
27
|
await createNapiLoader(uiThreadRpc, config.napiModulesMap);
|
|
28
28
|
const nativeLynx = createBackgroundLynx(config, nativeApp, mainThreadRpc, uiThreadRpc);
|
|
29
29
|
lynxCore.then(({ loadCard, destroyCard, callDestroyLifetimeFun }) => {
|
|
30
|
-
loadCard(nativeApp,
|
|
30
|
+
loadCard(nativeApp, {
|
|
31
|
+
...config,
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
updateData: config.initData,
|
|
34
|
+
}, nativeLynx);
|
|
31
35
|
registerDisposeHandler(uiThreadRpc, nativeApp, destroyCard, callDestroyLifetimeFun);
|
|
32
36
|
});
|
|
33
37
|
});
|
|
@@ -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 { flushElementTreeEndpoint, mainThreadStartEndpoint, postOffscreenEventEndpoint, reportErrorEndpoint, } from '@lynx-js/web-constants';
|
|
4
|
+
import { flushElementTreeEndpoint, mainThreadStartEndpoint, postOffscreenEventEndpoint, reportErrorEndpoint, dispatchLynxViewEventEndpoint, i18nResourceMissedEventName, I18nResources, updateI18nResourcesEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { createMarkTimingInternal } from './crossThreadHandlers/createMainthreadMarkTimingInternal.js';
|
|
7
7
|
import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
|
|
@@ -14,15 +14,28 @@ export function startMainThreadWorker(uiThreadPort, backgroundThreadPort) {
|
|
|
14
14
|
const markTimingInternal = createMarkTimingInternal(backgroundThreadRpc);
|
|
15
15
|
const uiFlush = uiThreadRpc.createCall(flushElementTreeEndpoint);
|
|
16
16
|
const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
|
|
17
|
+
const triggerI18nResourceFallback = (options) => {
|
|
18
|
+
uiThreadRpc.invoke(dispatchLynxViewEventEndpoint, [
|
|
19
|
+
i18nResourceMissedEventName,
|
|
20
|
+
options,
|
|
21
|
+
]);
|
|
22
|
+
};
|
|
17
23
|
const docu = new OffscreenDocument({
|
|
18
24
|
onCommit: uiFlush,
|
|
19
25
|
});
|
|
26
|
+
const i18nResources = new I18nResources();
|
|
20
27
|
uiThreadRpc.registerHandler(postOffscreenEventEndpoint, docu[_onEvent]);
|
|
21
|
-
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, docu, docu.createElement.bind(docu), docu.commit.bind(docu), markTimingInternal, reportError)
|
|
28
|
+
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, docu, docu.createElement.bind(docu), docu.commit.bind(docu), markTimingInternal, reportError, triggerI18nResourceFallback, (initI18nResources) => {
|
|
29
|
+
i18nResources.setData(initI18nResources);
|
|
30
|
+
return i18nResources;
|
|
31
|
+
});
|
|
22
32
|
uiThreadRpc.registerHandler(mainThreadStartEndpoint, (config) => {
|
|
23
33
|
startMainThread(config).then((runtime) => {
|
|
24
34
|
registerUpdateDataHandler(uiThreadRpc, runtime);
|
|
25
35
|
});
|
|
26
36
|
});
|
|
37
|
+
uiThreadRpc?.registerHandler(updateI18nResourcesEndpoint, data => {
|
|
38
|
+
i18nResources.setData(data);
|
|
39
|
+
});
|
|
27
40
|
}
|
|
28
41
|
//# sourceMappingURL=startMainThread.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@lynx-js/offscreen-document": "0.1.
|
|
26
|
-
"@lynx-js/web-constants": "0.
|
|
27
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
28
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
25
|
+
"@lynx-js/offscreen-document": "0.1.2",
|
|
26
|
+
"@lynx-js/web-constants": "0.14.0",
|
|
27
|
+
"@lynx-js/web-mainthread-apis": "0.14.0",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.14.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@lynx-js/lynx-core": "0.1.2"
|