[IMP] reactivity: add support for collections (Set/Map WeakSet/WeakMap)

This commit is contained in:
Samuel Degueldre
2022-02-25 15:05:29 +01:00
committed by Géry Debongnie
parent 076b0d774e
commit d735213758
4 changed files with 747 additions and 64 deletions
@@ -28,6 +28,20 @@ exports[`reactivity in lifecycle can use a state hook 2 1`] = `
}"
`;
exports[`reactivity in lifecycle can use a state hook on Map 1`] = `
"function anonymous(bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
let block1 = createBlock(\`<div><block-text-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['counter'].get('value');
return block1([txt1]);
}
}"
`;
exports[`reactivity in lifecycle change state while mounting component 1`] = `
"function anonymous(bdom, helpers
) {
+12
View File
@@ -53,6 +53,18 @@ describe("reactivity in lifecycle", () => {
expect(n).toBe(2); // no new rendering occured: b was never read via state!
});
test("can use a state hook on Map", async () => {
class Counter extends Component {
static template = xml`<div><t t-esc="counter.get('value')"/></div>`;
counter = useState(new Map([["value", 42]]));
}
const counter = await mount(Counter, fixture);
expect(fixture.innerHTML).toBe("<div>42</div>");
counter.counter.set("value", 3);
await nextTick();
expect(fixture.innerHTML).toBe("<div>3</div>");
});
test("state changes in willUnmount do not trigger rerender", async () => {
const steps: string[] = [];
class Child extends Component {