mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
0717fe241d
Have a t-ref on a DOM node with a t-key. Change the t-key. Before this commit, the old block removed its element from the component's refs *after* the new block had been mounted, meaning that in effect, the resulting ref at the end of the whole patch was null. After this commit, we only remove an element from the component's ref if that very same element was indeed the ref. (otherwise it means someone else has changed the ref.)
145 lines
4.5 KiB
Plaintext
145 lines
4.5 KiB
Plaintext
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
exports[`refs basic use 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { singleRefSetter } = helpers;
|
|
|
|
let block1 = createBlock(\`<div block-ref=\\"0\\"/>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const refs = this.__owl__.refs;
|
|
const ref1 = singleRefSetter(refs, \`div\`);
|
|
return block1([ref1]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`refs can use 2 refs with same name in a t-if/t-else situation 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { singleRefSetter, multiRefSetter } = helpers;
|
|
|
|
let block2 = createBlock(\`<div block-ref=\\"0\\"/>\`);
|
|
let block3 = createBlock(\`<span block-ref=\\"0\\"/>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const refs = this.__owl__.refs;
|
|
const ref1 = multiRefSetter(refs, \`coucou\`);
|
|
let b2,b3;
|
|
if (ctx['state'].value) {
|
|
b2 = block2([ref1]);
|
|
} else {
|
|
b3 = block3([ref1]);
|
|
}
|
|
return multi([b2, b3]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`refs refs and recursive templates 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { singleRefSetter } = helpers;
|
|
const comp1 = app.createComponent(\`Test\`, true, false, false, false);
|
|
|
|
let block1 = createBlock(\`<p block-ref=\\"0\\"><block-text-1/><block-child-0/></p>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const refs = this.__owl__.refs;
|
|
const ref1 = singleRefSetter(refs, \`root\`);
|
|
let b2;
|
|
let txt1 = ctx['props'].tree.value;
|
|
if (ctx['props'].tree.child) {
|
|
b2 = comp1({tree: ctx['props'].tree.child}, key + \`__1\`, node, this, null);
|
|
}
|
|
return block1([ref1, txt1], [b2]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`refs refs and t-key 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { singleRefSetter } = helpers;
|
|
|
|
let block2 = createBlock(\`<button block-handler-0=\\"click\\"/>\`);
|
|
let block3 = createBlock(\`<p block-ref=\\"0\\"/>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const refs = this.__owl__.refs;
|
|
const ref1 = singleRefSetter(refs, \`root\`);
|
|
const v1 = ctx['state'];
|
|
let hdlr1 = [()=>v1.renderId++, ctx];
|
|
const b2 = block2([hdlr1]);
|
|
const tKey_1 = ctx['state'].renderId;
|
|
const b3 = toggler(tKey_1, block3([ref1]));
|
|
return multi([b2, b3]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`refs refs are properly bound in slots 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { capture, singleRefSetter, markRaw } = helpers;
|
|
const comp1 = app.createComponent(\`Dialog\`, true, true, false, true);
|
|
|
|
let block1 = createBlock(\`<div><span class=\\"counter\\"><block-text-0/></span><block-child-0/></div>\`);
|
|
let block2 = createBlock(\`<button block-handler-0=\\"click\\" block-ref=\\"1\\">do something</button>\`);
|
|
|
|
function slot1(ctx, node, key = \\"\\") {
|
|
const refs = this.__owl__.refs;
|
|
const ref1 = singleRefSetter(refs, \`myButton\`);
|
|
let hdlr1 = [ctx['doSomething'], ctx];
|
|
return block2([hdlr1, ref1]);
|
|
}
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
let txt1 = ctx['state'].val;
|
|
const ctx1 = capture(ctx);
|
|
const b3 = comp1({slots: markRaw({'footer': {__render: slot1.bind(this), __ctx: ctx1}})}, key + \`__1\`, node, this, null);
|
|
return block1([txt1], [b3]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`refs refs are properly bound in slots 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { callSlot } = helpers;
|
|
|
|
let block1 = createBlock(\`<span><block-child-0/></span>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const b2 = callSlot(ctx, node, key, 'footer', false, {});
|
|
return block1([], [b2]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`refs throws if there are 2 same refs at the same time 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
let { singleRefSetter, multiRefSetter } = helpers;
|
|
|
|
let block2 = createBlock(\`<div block-ref=\\"0\\"/>\`);
|
|
let block3 = createBlock(\`<span block-ref=\\"0\\"/>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const refs = this.__owl__.refs;
|
|
const ref1 = multiRefSetter(refs, \`coucou\`);
|
|
const b2 = block2([ref1]);
|
|
const b3 = block3([ref1]);
|
|
return multi([b2, b3]);
|
|
}
|
|
}"
|
|
`;
|