// Copyright 2024 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 { reloadMainThread } from './reload-main-thread.js'; import { applyUpdatePageData } from '../../core/lynx-page-data.js'; import { createElementTemplatePage, setupPage } from '../runtime/page/page.js'; import { renderMainThread } from '../runtime/render/render-main-thread.js'; function injectCalledByNative(): void { const calledByNative: LynxCallByNative = { renderPage, updatePage, updateGlobalProps, getPageData: function() { return null; }, removeComponents: function(): void {}, }; Object.assign(globalThis, calledByNative); } function renderPage(data: Record | undefined): void { lynx.__initData = data ?? {}; setupPage(createElementTemplatePage()); renderMainThread(); } function updatePage(data: Record | undefined, options?: UpdatePageOption): void { if (__FIRST_SCREEN_SYNC_TIMING__ !== 'immediately') { return; } if (options?.reloadTemplate) { reloadMainThread(data, options); return; } applyUpdatePageData(data, options); __FlushElementTree(undefined, options ?? {}); } function updateGlobalProps(_data: unknown, options?: UpdatePageOption): void { if (options) { __FlushElementTree(undefined, options); } else { __FlushElementTree(); } } /** * @internal */ export { injectCalledByNative };