Use === when rhs is string

This commit is contained in:
Aster 2022-02-12 21:22:05 +08:00
parent cc79287e86
commit 2d1371167f

View file

@ -102,15 +102,15 @@ export class Interpreter {
SetAttribute(root, field, value, ns) { SetAttribute(root, field, value, ns) {
const name = field; const name = field;
const node = this.nodes[root]; const node = this.nodes[root];
if (ns == "style") { if (ns === "style") {
// @ts-ignore // @ts-ignore
node.style[name] = value; node.style[name] = value;
} else if (ns != null || ns != undefined) { } else if (ns != null || ns !== undefined) {
node.setAttributeNS(ns, name, value); node.setAttributeNS(ns, name, value);
} else { } else {
switch (name) { switch (name) {
case "value": case "value":
if (value != node.value) { if (value !== node.value) {
node.value = value; node.value = value;
} }
break; break;
@ -125,7 +125,7 @@ export class Interpreter {
break; break;
default: default:
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if (value == "false" && bool_attrs.hasOwnProperty(name)) { if (value === "false" && bool_attrs.hasOwnProperty(name)) {
node.removeAttribute(name); node.removeAttribute(name);
} else { } else {
node.setAttribute(name, value); node.setAttribute(name, value);
@ -142,7 +142,7 @@ export class Interpreter {
node.checked = false; node.checked = false;
} else if (name === "selected") { } else if (name === "selected") {
node.selected = false; node.selected = false;
} else if (name == "dangerous_inner_html") { } else if (name === "dangerous_inner_html") {
node.innerHTML = ""; node.innerHTML = "";
} else { } else {
node.removeAttribute(name); node.removeAttribute(name);
@ -200,10 +200,10 @@ export class Interpreter {
`dioxus-prevent-default` `dioxus-prevent-default`
); );
if (event.type == "click") { if (event.type === "click") {
// todo call prevent default if it's the right type of event // todo call prevent default if it's the right type of event
if (shouldPreventDefault !== `onclick`) { if (shouldPreventDefault !== `onclick`) {
if (target.tagName == "A") { if (target.tagName === "A") {
event.preventDefault(); event.preventDefault();
const href = target.getAttribute("href"); const href = target.getAttribute("href");
if (href !== "" && href !== null && href !== undefined) { if (href !== "" && href !== null && href !== undefined) {
@ -213,7 +213,7 @@ export class Interpreter {
} }
// also prevent buttons from submitting // also prevent buttons from submitting
if (target.tagName == "BUTTON") { if (target.tagName === "BUTTON") {
event.preventDefault(); event.preventDefault();
} }
} }
@ -237,16 +237,16 @@ export class Interpreter {
if (shouldPreventDefault === `on${event.type}`) { if (shouldPreventDefault === `on${event.type}`) {
event.preventDefault(); event.preventDefault();
} }
if (event.type == "submit") { if (event.type === "submit") {
event.preventDefault(); event.preventDefault();
} }
if (target.tagName == "FORM") { if (target.tagName === "FORM") {
for (let x = 0; x < target.elements.length; x++) { for (let x = 0; x < target.elements.length; x++) {
let element = target.elements[x]; let element = target.elements[x];
let name = element.getAttribute("name"); let name = element.getAttribute("name");
if (name != null) { if (name != null) {
if (element.getAttribute("type") == "checkbox") { if (element.getAttribute("type") === "checkbox") {
// @ts-ignore // @ts-ignore
contents.values[name] = element.checked ? "true" : "false"; contents.values[name] = element.checked ? "true" : "false";
} else { } else {
@ -349,7 +349,7 @@ export function serialize_event(event) {
case "submit": { case "submit": {
let target = event.target; let target = event.target;
let value = target.value ?? target.textContent; let value = target.value ?? target.textContent;
if (target.type == "checkbox") { if (target.type === "checkbox") {
value = target.checked ? "true" : "false"; value = target.checked ? "true" : "false";
} }
return { return {