mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] vdom: remove handling of combined selectors
this is done by qweb anyway
This commit is contained in:
+2
-10
@@ -176,18 +176,10 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
|
|||||||
}
|
}
|
||||||
vnode.elm = api.createComment(vnode.text as string);
|
vnode.elm = api.createComment(vnode.text as string);
|
||||||
} else if (sel !== undefined) {
|
} else if (sel !== undefined) {
|
||||||
// Parse selector
|
|
||||||
const hashIdx = sel.indexOf("#");
|
|
||||||
const dotIdx = sel.indexOf(".", hashIdx);
|
|
||||||
const hash = hashIdx > 0 ? hashIdx : sel.length;
|
|
||||||
const dot = dotIdx > 0 ? dotIdx : sel.length;
|
|
||||||
const tag = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel;
|
|
||||||
const elm = (vnode.elm =
|
const elm = (vnode.elm =
|
||||||
isDef(data) && isDef((i = (data as VNodeData).ns))
|
isDef(data) && isDef((i = (data as VNodeData).ns))
|
||||||
? api.createElementNS(i, tag)
|
? api.createElementNS(i, sel)
|
||||||
: api.createElement(tag));
|
: api.createElement(sel));
|
||||||
if (hash < dot) elm.setAttribute("id", sel.slice(hash + 1, dot));
|
|
||||||
if (dotIdx > 0) elm.setAttribute("class", sel.slice(dot + 1).replace(/\./g, " "));
|
|
||||||
for (i = 0, iLen = cbs.create.length; i < iLen; ++i) cbs.create[i](emptyNode, vnode);
|
for (i = 0, iLen = cbs.create.length; i < iLen; ++i) cbs.create[i](emptyNode, vnode);
|
||||||
if (array(children)) {
|
if (array(children)) {
|
||||||
for (i = 0, iLen = children.length; i < iLen; ++i) {
|
for (i = 0, iLen = children.length; i < iLen; ++i) {
|
||||||
|
|||||||
@@ -185,20 +185,6 @@ describe("snabbdom", function() {
|
|||||||
expect(elm.tagName).toBe("DIV");
|
expect(elm.tagName).toBe("DIV");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("has different tag and id", function() {
|
|
||||||
let elm: any = document.createElement("div");
|
|
||||||
vnode0.appendChild(elm);
|
|
||||||
const vnode1 = h("span#id");
|
|
||||||
elm = patch(elm, vnode1).elm;
|
|
||||||
expect(elm.tagName).toBe("SPAN");
|
|
||||||
expect(elm.id).toBe("id");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("has id", function() {
|
|
||||||
elm = patch(vnode0, h("div", [h("div#unique")])).elm;
|
|
||||||
expect(elm.firstChild.id).toBe("unique");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("has correct namespace", function() {
|
test("has correct namespace", function() {
|
||||||
const SVGNamespace = "http://www.w3.org/2000/svg";
|
const SVGNamespace = "http://www.w3.org/2000/svg";
|
||||||
const XHTMLNamespace = "http://www.w3.org/1999/xhtml";
|
const XHTMLNamespace = "http://www.w3.org/1999/xhtml";
|
||||||
@@ -218,20 +204,6 @@ describe("snabbdom", function() {
|
|||||||
expect(elm.firstChild.firstChild.namespaceURI).toBe(XHTMLNamespace);
|
expect(elm.firstChild.firstChild.namespaceURI).toBe(XHTMLNamespace);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("receives classes in selector", function() {
|
|
||||||
elm = patch(vnode0, h("div", [h("i.am.a.class")])).elm;
|
|
||||||
expect(elm.firstChild.classList.contains("am")).toBeTruthy();
|
|
||||||
expect(elm.firstChild.classList.contains("a")).toBeTruthy();
|
|
||||||
expect(elm.firstChild.classList.contains("class")).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("receives classes in selector when namespaced", function() {
|
|
||||||
elm = patch(vnode0, h("svg", [h("g.am.a.class.too")])).elm;
|
|
||||||
expect(elm.firstChild.classList.contains("am")).toBeTruthy();
|
|
||||||
expect(elm.firstChild.classList.contains("a")).toBeTruthy();
|
|
||||||
expect(elm.firstChild.classList.contains("class")).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can create elements with text content", function() {
|
test("can create elements with text content", function() {
|
||||||
elm = patch(vnode0, h("div", ["I am a string"])).elm;
|
elm = patch(vnode0, h("div", ["I am a string"])).elm;
|
||||||
expect(elm.innerHTML).toBe("I am a string");
|
expect(elm.innerHTML).toBe("I am a string");
|
||||||
@@ -268,26 +240,6 @@ describe("snabbdom", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("patching an element", function() {
|
describe("patching an element", function() {
|
||||||
test("changes the elements classes", function() {
|
|
||||||
const vnode1 = h("i.i.am.horse");
|
|
||||||
const vnode2 = h("i.i.am");
|
|
||||||
patch(vnode0, vnode1);
|
|
||||||
elm = patch(vnode1, vnode2).elm;
|
|
||||||
expect(elm.classList.contains("i")).toBeTruthy();
|
|
||||||
expect(elm.classList.contains("am")).toBeTruthy();
|
|
||||||
expect(!elm.classList.contains("horse")).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("removes missing classes", function() {
|
|
||||||
const vnode1 = h("i.i.am.horse");
|
|
||||||
const vnode2 = h("i.i.am");
|
|
||||||
patch(vnode0, vnode1);
|
|
||||||
elm = patch(vnode1, vnode2).elm;
|
|
||||||
expect(elm.classList.contains("i")).toBeTruthy();
|
|
||||||
expect(elm.classList.contains("am")).toBeTruthy();
|
|
||||||
expect(!elm.classList.contains("horse")).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("changes an elements props", function() {
|
test("changes an elements props", function() {
|
||||||
const vnode1 = h("a", { props: { src: "http://other/" } });
|
const vnode1 = h("a", { props: { src: "http://other/" } });
|
||||||
const vnode2 = h("a", { props: { src: "http://localhost/" } });
|
const vnode2 = h("a", { props: { src: "http://localhost/" } });
|
||||||
|
|||||||
Reference in New Issue
Block a user