mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: use reactivity to allow shallow renderings
With this commit, component only render child components if they have different props (shallow equality). Otherwise, we trust the reactivity system to make sure that all impacted components are updated
This commit is contained in:
committed by
Samuel Degueldre
parent
592d9a458e
commit
1ae9d514b9
@@ -4,6 +4,7 @@ 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);
|
||||
@@ -16,7 +17,7 @@ exports[`Memo if no prop change, prevent renderings from above 1`] = `
|
||||
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: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__1\`, node, ctx);
|
||||
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]);
|
||||
}
|
||||
}"
|
||||
@@ -26,6 +27,7 @@ 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);
|
||||
@@ -33,7 +35,7 @@ exports[`Memo if no props, prevent renderings from above 1`] = `
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2 = component(\`Child\`, {value: ctx['state'].value}, key + \`__1\`, node, ctx);
|
||||
let b4 = component(\`Memo\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__3\`, node, ctx);
|
||||
let b4 = component(\`Memo\`, {slots: markRaw({'default': {__render: slot1, __ctx: ctx}})}, key + \`__3\`, node, ctx);
|
||||
return multi([b2, b4]);
|
||||
}
|
||||
}"
|
||||
@@ -54,6 +56,7 @@ exports[`Memo if no props, prevent renderings from above (work with simple html)
|
||||
"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);
|
||||
@@ -61,7 +64,7 @@ exports[`Memo if no props, prevent renderings from above (work with simple html)
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2 = text(ctx['state'].value);
|
||||
let b4 = component(\`Memo\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__1\`, node, ctx);
|
||||
let b4 = component(\`Memo\`, {slots: markRaw({'default': {__render: slot1, __ctx: ctx}})}, key + \`__1\`, node, ctx);
|
||||
return multi([b2, b4]);
|
||||
}
|
||||
}"
|
||||
|
||||
@@ -149,6 +149,7 @@ exports[`Portal Portal composed with t-slot 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
let { markRaw } = helpers;
|
||||
|
||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
||||
|
||||
@@ -157,7 +158,7 @@ exports[`Portal Portal composed with t-slot 1`] = `
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b3 = component(\`Child\`, {slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__2\`, node, ctx);
|
||||
let b3 = component(\`Child\`, {slots: markRaw({'default': {__render: slot1, __ctx: ctx}})}, key + \`__2\`, node, ctx);
|
||||
return block1([], [b3]);
|
||||
}
|
||||
}"
|
||||
|
||||
@@ -421,6 +421,7 @@ describe("Portal", () => {
|
||||
addOutsideDiv(fixture);
|
||||
const parent = await mount(Parent, fixture);
|
||||
expect(steps).toEqual(["parent:mounted"]);
|
||||
expect(fixture.innerHTML).toBe('<div id="outside"></div><div></div>');
|
||||
|
||||
parent.state.hasChild = true;
|
||||
await nextTick();
|
||||
@@ -430,6 +431,7 @@ describe("Portal", () => {
|
||||
"child:mounted",
|
||||
"parent:patched",
|
||||
]);
|
||||
expect(fixture.innerHTML).toBe('<div id="outside"><span>1</span></div><div></div>');
|
||||
|
||||
parent.state.val = 2;
|
||||
await nextTick();
|
||||
@@ -443,6 +445,7 @@ describe("Portal", () => {
|
||||
"child:patched",
|
||||
"parent:patched",
|
||||
]);
|
||||
expect(fixture.innerHTML).toBe('<div id="outside"><span>2</span></div><div></div>');
|
||||
|
||||
parent.state.hasChild = false;
|
||||
await nextTick();
|
||||
@@ -459,6 +462,7 @@ describe("Portal", () => {
|
||||
"child:willUnmount",
|
||||
"parent:patched",
|
||||
]);
|
||||
expect(fixture.innerHTML).toBe('<div id="outside"></div><div></div>');
|
||||
});
|
||||
|
||||
test("portal destroys on crash", async () => {
|
||||
|
||||
Reference in New Issue
Block a user