Minor Changes
-
1abf8f0: feat(web):
This is a breaking change
- A new param for
lynx-view
:nativeModulesUrl
, which allows you to pass an esm url to add a new module toNativeModules
. And we bind thenativeModulesCall
method to each function on the module, runthis.nativeModulesCall()
to trigger onNativeModulesCall.
export type NativeModuleHandlerContext = { nativeModulesCall: (name: string, data: Cloneable) => Promise<Cloneable>; };
a simple case:
lynxView.nativeModules = URL.createObjectURL( new Blob( [ `export default { myNativeModules: { async getColor(data, callback) { // trigger onNativeModulesCall and get the result const color = await this.nativeModulesCall('getColor', data); // return the result to caller callback(color); }, } };`, ], { type: 'text/javascript' }, ), );
onNativeModulesCall
is no longer the value handler ofNativeModules.bridge.call
, it will be the value handler of allNativeModules
modules.
Warning: This is a breaking change.
Before this commit, you listen to
NativeModules.bridge.call('getColor')
like this:lynxView.onNativeModulesCall = (name, data, callback) => { if (name === 'getColor') { callback(data.color); } };
Now you should use it like this:
lynxView.onNativeModulesCall = (name, data, moduleName) => { if (name === 'getColor' && moduleName === 'bridge') { return data.color; } };
You need to use
moduleName
to determine the NativeModules-module. And you don’t need to run callback, just return the result! - A new param for
Patch Changes
- @lynx-js/web-worker-rpc@0.7.0