- Set created with
data = signal.Set(new Set());
- Using
data().has(...) on a template.
- Adding another element in the set
data().add(...) (not the one observed)
- The templare re-renders anyway.
import { Component, mount, xml, signal, onPatched } from "@odoo/owl";
class Root extends Component {
static template = xml`<div>Hello Owl! <t t-out="this.data().has(1)"/></div>`;
data = signal.Set(new Set());
setup() {
onPatched(() => console.log("patched"));
setTimeout(() => this.data().add(2), 100);
}
}
mount(Root, document.body, { templates: TEMPLATES, dev: true });
The bug is not present if using data = proxy(new Set()); instead (and removing () from callers)
import { Component, mount, xml, signal, onPatched, proxy } from "@odoo/owl";
class Root extends Component {
static template = xml`<div>Hello Owl! <t t-out="this.data.has(1)"/></div>`;
data = proxy(new Set());
setup() {
onPatched(() => console.log("patched"));
setTimeout(() => this.data.add(2), 100);
}
}
mount(Root, document.body, { templates: TEMPLATES, dev: true });
signal.Set is supposed to be more efficient as it is shallow (?), but in practice proxy performs better.
Is it a bug or do I miss something?
data = signal.Set(new Set());data().has(...)on a template.data().add(...)(not the one observed)The bug is not present if using
data = proxy(new Set());instead (and removing()from callers)signal.Setis supposed to be more efficient as it is shallow (?), but in practiceproxyperforms better.Is it a bug or do I miss something?