Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/hot-crabs-pick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lynx-js/web-mainthread-apis": patch
"@lynx-js/web-constants": patch
"@lynx-js/web-core": patch
---

refactor: clean the decodeOperations implementation
1 change: 1 addition & 0 deletions packages/web-platform/web-constants/src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const flushElementTreeEndpoint = createRpcEndpoint<
operations: ElementOperation[],
FlushElementTreeOptions,
styleContent: string | undefined,
timingFlags: string[],
],
void
>('flushElementTree', false, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ export function registerFlushElementTreeHandler(
};
mainThreadRpc.registerHandler(
endpoint,
(operations, options, cardCss) => {
(operations, options, cardCss, timingFlags) => {
const { pipelineOptions } = options;
const pipelineId = pipelineOptions?.pipelineID;
const timingFlags: string[] = [];
markTimingInternal('dispatch_start', pipelineId);
markTimingInternal('layout_start', pipelineId);
markTimingInternal('ui_operation_flush_start', pipelineId);
const page = decodeElementOperation(operations, {
timingFlags,
uniqueIdToElement,
uniqueIdToCssInJsRule,
createElementImpl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export function decodeElementOperation<
>(
operations: ElementOperation[],
options: {
timingFlags: string[];
uniqueIdToElement: (WeakRef<T> | undefined)[];
uniqueIdToCssInJsRule: (WeakRef<CSSStyleRule> | undefined)[];
createElementImpl: (tag: string) => T;
Expand All @@ -93,7 +92,6 @@ export function decodeElementOperation<
createElementImpl,
createStyleRuleImpl,
eventHandler,
timingFlags,
} = options;
let pageElement: T | undefined;

Expand Down Expand Up @@ -148,9 +146,6 @@ export function decodeElementOperation<
target.removeAttribute(op.key);
} else {
target.setAttribute(op.key, op.value);
if (op.value && op.key === __lynx_timing_flag) {
timingFlags.push(op.value);
}
if (op.key === lynxTagAttribute && op.value === 'page') {
pageElement = target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import {
genCssInJsInfo,
transformToWebCss,
} from './utils/processStyleInfo.js';
import { createAttributeAndPropertyFunctionsWithContext } from './elementAPI/attributeAndProperty/createAttributeAndPropertyFunctionsWithContext.js';

export interface MainThreadRuntimeCallbacks {
mainChunkReady: () => void;
flushElementTree: (
operations: ElementOperation[],
options: FlushElementTreeOptions,
styleContent?: string,
styleContent: string | undefined,
timingFlags: string[],
) => void;
_ReportError: (error: Error, info?: unknown) => void;
__OnLifecycleEvent: (lynxLifecycleEvents: LynxLifecycleEvent) => void;
Expand All @@ -54,6 +56,11 @@ export interface MainThreadConfig {
export class MainThreadRuntime {
private isFp = true;

/**
* @private
*/
_timingFlags: string[] = [];

public operationsRef: {
operations: ElementOperation[];
} = {
Expand All @@ -71,6 +78,7 @@ export class MainThreadRuntime {
: genCssInJsInfo(this.config.styleInfo);
Object.assign(
this,
createAttributeAndPropertyFunctionsWithContext(this),
attributeAndPropertyApis,
domTreeApis,
eventApis,
Expand Down Expand Up @@ -146,7 +154,9 @@ export class MainThreadRuntime {
options: FlushElementTreeOptions,
) => {
const operations = this.operationsRef.operations;
const timingFlags = this._timingFlags;
this.operationsRef.operations = [];
this._timingFlags = [];
this.config.callbacks.flushElementTree(
operations,
options,
Expand All @@ -156,6 +166,7 @@ export class MainThreadRuntime {
this.config.pageConfig,
)
: undefined,
timingFlags,
);
this.isFp = false;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ export function __GetTag(element: ElementThreadElement): string {
return element.getAttribute(lynxTagAttribute)!;
}

export function __SetAttribute(
element: ElementThreadElement,
key: string,
value: string | null | undefined,
): void {
element.setAttribute(key, value ?? null);
}

export function __SetConfig(
element: ElementThreadElement,
config: Record<string, any>,
Expand All @@ -104,7 +96,7 @@ export function __UpdateComponentID(
element: ElementThreadElement,
componentID: string,
) {
__SetAttribute(element, componentIdAttribute, componentID);
element.setAttribute(componentIdAttribute, componentID);
}

export function __GetConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { __lynx_timing_flag } from '@lynx-js/web-constants';
import type { MainThreadRuntime } from '../../MainThreadRuntime.js';
import type { ElementThreadElement } from '../ElementThreadElement.js';

export function createAttributeAndPropertyFunctionsWithContext(
runtime: MainThreadRuntime,
) {
function __SetAttribute(
element: ElementThreadElement,
key: string,
value: string | null | undefined,
): void {
element.setAttribute(key, value ?? null);
if (key === __lynx_timing_flag && value) {
runtime._timingFlags.push(value);
}
}

return {
__SetAttribute,
};
}