mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] reactivity: add support for collections (Set/Map WeakSet/WeakMap)
This commit is contained in:
committed by
Géry Debongnie
parent
076b0d774e
commit
d735213758
@@ -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
|
||||
) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user