mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REM] remove the Memo component
With the new fine grained reactivity system, it was no longer useful.
This commit is contained in:
committed by
Samuel Degueldre
parent
8a472231cf
commit
2a1b99be2d
@@ -1,71 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Memo if no prop change, prevent renderings from above 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
let { markRaw } = helpers;
|
||||
|
||||
function slot1(ctx, node, key = \\"\\") {
|
||||
let b6 = text(ctx['state'].a);
|
||||
let b7 = text(ctx['state'].b);
|
||||
let b8 = text(ctx['state'].c);
|
||||
return multi([b6, b7, b8]);
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2 = text(ctx['state'].a);
|
||||
let b3 = text(ctx['state'].b);
|
||||
let b4 = text(ctx['state'].c);
|
||||
let b9 = component(\`Memo\`, {a: ctx['state'].a, b: ctx['state'].b,slots: markRaw({'default': {__render: slot1, __ctx: ctx}})}, key + \`__1\`, node, ctx);
|
||||
return multi([b2, b3, b4, b9]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Memo if no props, prevent renderings from above 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
let { markRaw } = helpers;
|
||||
|
||||
function slot1(ctx, node, key = \\"\\") {
|
||||
return component(\`Child\`, {value: ctx['state'].value}, key + \`__2\`, node, ctx);
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2 = component(\`Child\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||
let b4 = component(\`Memo\`, {slots: markRaw({'default': {__render: slot1, __ctx: ctx}})}, key + \`__3\`, node, ctx);
|
||||
return multi([b2, b4]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Memo if no props, prevent renderings from above 2`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return text(ctx['props'].value);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Memo if no props, prevent renderings from above (work with simple html) 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
let { markRaw } = helpers;
|
||||
|
||||
function slot1(ctx, node, key = \\"\\") {
|
||||
return text(ctx['state'].value);
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2 = text(ctx['state'].value);
|
||||
let b4 = component(\`Memo\`, {slots: markRaw({'default': {__render: slot1, __ctx: ctx}})}, key + \`__1\`, node, ctx);
|
||||
return multi([b2, b4]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
@@ -1,92 +0,0 @@
|
||||
import { Component, mount, useState, xml } from "../../src";
|
||||
import { Memo } from "../../src/";
|
||||
import { makeTestFixture, nextTick, snapshotEverything } from "../helpers";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
snapshotEverything();
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
});
|
||||
|
||||
describe("Memo", () => {
|
||||
test("if no props, prevent renderings from above ", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<t t-esc="props.value"/>`;
|
||||
}
|
||||
class Test extends Component {
|
||||
static template = xml`
|
||||
<Child value="state.value"/>
|
||||
<Memo>
|
||||
<Child value="state.value"/>
|
||||
</Memo>`;
|
||||
|
||||
static components = { Memo, Child };
|
||||
|
||||
state = useState({ value: 1 });
|
||||
}
|
||||
|
||||
const component = await mount(Test, fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe("11");
|
||||
component.state.value = 2;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("21");
|
||||
});
|
||||
|
||||
test("if no props, prevent renderings from above (work with simple html) ", async () => {
|
||||
class Test extends Component {
|
||||
static template = xml`
|
||||
<t t-esc="state.value"/>
|
||||
<Memo>
|
||||
<t t-esc="state.value"/>
|
||||
</Memo>`;
|
||||
|
||||
static components = { Memo };
|
||||
|
||||
state = useState({ value: 1 });
|
||||
}
|
||||
|
||||
const component = await mount(Test, fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe("11");
|
||||
component.state.value = 2;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("21");
|
||||
});
|
||||
|
||||
test("if no prop change, prevent renderings from above ", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<t t-esc="props.value"/>`;
|
||||
}
|
||||
|
||||
class Test extends Component {
|
||||
static template = xml`
|
||||
<t t-esc="state.a"/>
|
||||
<t t-esc="state.b"/>
|
||||
<t t-esc="state.c"/>
|
||||
<Memo a="state.a" b="state.b">
|
||||
<t t-esc="state.a"/>
|
||||
<t t-esc="state.b"/>
|
||||
<t t-esc="state.c"/>
|
||||
</Memo>`;
|
||||
|
||||
static components = { Memo, Child };
|
||||
|
||||
state = useState({ a: "a", b: "b", c: "c" });
|
||||
}
|
||||
|
||||
const component = await mount(Test, fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe("abcabc");
|
||||
|
||||
component.state.c = "C";
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("abCabc");
|
||||
|
||||
component.state.a = "A";
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("AbCAbC");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user