Skip to content
Open
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
18 changes: 2 additions & 16 deletions renderers/lit/src/0.8/ui/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,10 @@ export class Checkbox extends Root {
];

#setBoundValue(value: boolean) {
if (!this.value || !this.processor) {
if (!this.value || !("path" in this.value) || !this.value.path) {
return;
}

if (!("path" in this.value)) {
return;
}

if (!this.value.path) {
return;
}

this.processor.setData(
this.component,
this.value.path,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.updateBoundData(this.value.path, value);
}

#renderField(value: boolean | number) {
Expand Down
18 changes: 2 additions & 16 deletions renderers/lit/src/0.8/ui/datetime-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,10 @@ export class DateTimeInput extends Root {
];

#setBoundValue(value: string) {
if (!this.value || !this.processor) {
if (!this.value || !("path" in this.value) || !this.value.path) {
return;
}

if (!("path" in this.value)) {
return;
}

if (!this.value.path) {
return;
}

this.processor.setData(
this.component,
this.value.path,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.updateBoundData(this.value.path, value);
}

#renderField(value: string) {
Expand Down
15 changes: 14 additions & 1 deletion renderers/lit/src/0.8/ui/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { map } from "lit/directives/map.js";
import { effect } from "signal-utils/subtle/microtask-effect";
import { A2uiMessageProcessor } from "@a2ui/web_core/data/model-processor";
import { StringValue } from "@a2ui/web_core/types/primitives";
import { AnyComponentNode, SurfaceID, Theme } from "@a2ui/web_core/types/types";
import { AnyComponentNode, DataValue, SurfaceID, Theme } from "@a2ui/web_core/types/types";
import { themeContext } from "./context/theme.js";
import { structuralStyles } from "./styles.js";
import { componentRegistry } from "./component-registry.js";
Expand Down Expand Up @@ -76,6 +76,19 @@ export class Root extends SignalWatcher(LitElement) {

#weight: string | number = 1;

protected updateBoundData(relativePath: string, value: DataValue) {
if (!this.processor) {
return;
}
this.processor.setData(
this.component,
relativePath,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.requestUpdate();
}
Comment on lines +79 to +90
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The updateBoundData helper should verify that this.component is not null before proceeding. While processor.setData includes an internal check and logs a warning, explicitly checking it here prevents an unnecessary call and a redundant requestUpdate() when the component context is missing. This ensures the helper only executes when the component is fully initialized and attached to a node.

Suggested change
protected updateBoundData(relativePath: string, value: DataValue) {
if (!this.processor) {
return;
}
this.processor.setData(
this.component,
relativePath,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.requestUpdate();
}
protected updateBoundData(relativePath: string, value: DataValue) {
if (!this.processor || !this.component) {
return;
}
this.processor.setData(
this.component,
relativePath,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.requestUpdate();
}


static styles = [
structuralStyles,
css`
Expand Down
19 changes: 2 additions & 17 deletions renderers/lit/src/0.8/ui/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { customElement, property } from "lit/decorators.js";
import { Root } from "./root.js";
import { A2uiMessageProcessor } from "@a2ui/web_core/data/model-processor";
import * as Primitives from "@a2ui/web_core/types/primitives";
import * as Types from "@a2ui/web_core/types/types";
import { classMap } from "lit/directives/class-map.js";
import { styleMap } from "lit/directives/style-map.js";
import { structuralStyles } from "./styles.js";
Expand Down Expand Up @@ -62,24 +61,10 @@ export class Slider extends Root {
];

#setBoundValue(value: string) {
if (!this.value || !this.processor) {
if (!this.value || !("path" in this.value) || !this.value.path) {
return;
}

if (!("path" in this.value)) {
return;
}

if (!this.value.path) {
return;
}

this.processor.setData(
this.component,
this.value.path,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.updateBoundData(this.value.path, value);
}

#renderField(value: string | number) {
Expand Down
17 changes: 2 additions & 15 deletions renderers/lit/src/0.8/ui/text-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { html, css, nothing } from "lit";
import { customElement, property } from "lit/decorators.js";
import { Root } from "./root.js";
import { A2uiMessageProcessor } from "@a2ui/web_core/data/model-processor";
import * as Primitives from "@a2ui/web_core/types/primitives";
import * as Types from "@a2ui/web_core/types/types";
import { Events } from "@a2ui/web_core";
Expand Down Expand Up @@ -76,22 +75,10 @@ export class TextField extends Root {
];

#setBoundValue(value: string) {
if (!this.text || !this.processor) {
if (!this.text || !("path" in this.text) || !this.text.path) {
return;
}
if (!("path" in this.text)) {
return;
}
if (!this.text.path) {
return;
}

this.processor.setData(
this.component,
this.text.path,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.updateBoundData(this.text.path, value);
}

#renderField(value: string | number, label: string) {
Expand Down