@lynx-js/web-core
Version:
This is an internal experimental package, do not use
41 lines • 1.74 kB
JavaScript
// Copyright 2023 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { dispatchCoreContextOnBackgroundEndpoint, dispatchJSContextOnMainThreadEndpoint, reloadEndpoint, } from '../../endpoints.js';
import { createGetCustomSection } from './crossThreadHandlers/createGetCustomSection.js';
import { createElement } from './createElement.js';
import { LynxCrossThreadContext } from '../../LynxCrossThreadContext.js';
export function createBackgroundLynx(globalProps, customSections, nativeApp, mainThreadRpc) {
const coreContext = new LynxCrossThreadContext({
rpc: mainThreadRpc,
receiveEventEndpoint: dispatchCoreContextOnBackgroundEndpoint,
sendEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
});
return {
__globalProps: globalProps,
getJSModule(_moduleName) {
},
getNativeApp() {
return nativeApp;
},
getCoreContext() {
return coreContext;
},
getCustomSectionSync(key) {
return customSections[key];
},
getCustomSection: createGetCustomSection(mainThreadRpc, customSections),
queueMicrotask: (callback) => {
queueMicrotask(callback);
},
createElement(_, id) {
return createElement(id, mainThreadRpc);
},
getI18nResource: () => nativeApp.i18nResource.data,
QueryComponent: (source, callback) => nativeApp.queryComponent(source, callback),
reload: () => {
mainThreadRpc.invoke(reloadEndpoint, []);
},
};
}
//# sourceMappingURL=createBackgroundLynx.js.map