Skip to content

Commit bc2428d

Browse files
authored
Don't bubble events past first listener in our vdom implementation (#97)
(+ other fixes) This is a short-term solution, we probably want a way to still allow bubbling. Let's wait until the need shows up.
1 parent 6069bca commit bc2428d

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

typescript/packages/common-ui/src/hyperscript/render.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const listen = (
6565

6666
/** Read an event, returning a safe description object */
6767
const readEvent = (event: Event) => {
68+
event.stopPropagation();
6869
switch (event.type) {
6970
case "click":
7071
return {
@@ -210,7 +211,7 @@ const renderText = (element: Element, value: any): Cancel =>
210211
const __id__ = Symbol("list item key");
211212

212213
let _cid = 0;
213-
const cid = () => `cid${_cid++}`
214+
const cid = () => `cid${_cid++}`;
214215

215216
/**
216217
* An element with an id symbol used for efficient rendering of dynamic lists.
@@ -233,13 +234,7 @@ export const renderDynamicChildren = (
233234
// item will not be efficiently re-rendered by identity, but it will
234235
// still work.
235236
const statesById = new Map(
236-
gmap(
237-
states,
238-
(state) => [
239-
state.id ?? cid(),
240-
state
241-
]
242-
)
237+
gmap(states, (state) => [state.id ?? cid(), state])
243238
);
244239

245240
// Build an index of children and a list of children to remove.

typescript/packages/lookslike-high-level/src/components/saga-link.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,6 @@ export class CommonSagaLink extends LitElement {
7171
);
7272
}
7373

74-
override connectedCallback() {
75-
super.connectedCallback();
76-
this.maybeListenToName();
77-
}
78-
79-
override disconnectedCallback() {
80-
super.disconnectedCallback();
81-
this.nameEffect?.();
82-
}
83-
84-
override updated(changedProperties: Map<string | number | symbol, unknown>) {
85-
super.updated(changedProperties);
86-
if (changedProperties.has("saga")) {
87-
this.maybeListenToName(true);
88-
}
89-
}
90-
91-
private maybeListenToName(skipUpdate = false) {
92-
if (signal.isSignal(this.saga?.[NAME])) {
93-
this.nameEffect = signal.effect([this.saga[NAME]], (name: string) => {
94-
this.nameFromGem = name;
95-
if (!skipUpdate) this.requestUpdate();
96-
skipUpdate = false;
97-
});
98-
} else {
99-
this.nameEffect?.();
100-
this.nameFromGem = this.saga?.[NAME];
101-
}
102-
}
103-
10474
override render() {
10575
if (!this.saga) return html``;
10676
const name = this.name ?? this.nameFromGem;

typescript/packages/lookslike-high-level/src/recipes/todo-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { signal, stream } from "@commontools/common-frp";
33
import { recipe, NAME } from "../recipe.js";
44
import { annotation } from "../components/annotation.js";
55
const { binding, repeat } = view;
6-
const { list, vstack, include, sendInput, todo, commonInput } = tags;
6+
const { vstack, include, sendInput, todo, commonInput } = tags;
77
const { state, computed } = signal;
88
const { subject } = stream;
99

0 commit comments

Comments
 (0)