Skip to content

Commit 86792d8

Browse files
committed
Cleanup and optimizations
1 parent 2eec2a1 commit 86792d8

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/render.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const h = (type, p, ...args) => {
9797
//@ts-ignore
9898
if (raw === false && type instanceof Function) {
9999
return type(
100-
children != EMPTY_CHILDREN ? { children, ...props } : props,
100+
children != EMPTY_CHILDREN ? { children, ...props } : props
101101
);
102102
}
103103

@@ -178,11 +178,11 @@ function diff(newVnode, node, id = ID, hydrate, isSvg) {
178178
: isSvg
179179
? $.createElementNS(
180180
"http://www.w3.org/2000/svg",
181-
newVnode.type,
181+
newVnode.type
182182
)
183183
: $.createElement(
184184
newVnode.type,
185-
newVnode.is ? { is: newVnode.is } : undefined,
185+
newVnode.is ? { is: newVnode.is } : undefined
186186
);
187187
}
188188
}
@@ -229,7 +229,7 @@ function diff(newVnode, node, id = ID, hydrate, isSvg) {
229229
id,
230230
// add support to foreignObject, children will escape from svg
231231
!cycle && hydrate,
232-
isSvg && newVnode.type == "foreignObject" ? false : isSvg,
232+
isSvg && newVnode.type == "foreignObject" ? false : isSvg
233233
);
234234
}
235235

@@ -312,7 +312,7 @@ export function renderChildren(children, fragment, parent, id, hydrate, isSvg) {
312312

313313
children &&
314314
flat(children, (child) => {
315-
if (typeof child == "object" && child.$$ != $$) {
315+
if (isObject(child) && child.$$ != $$) {
316316
return;
317317
}
318318

@@ -489,7 +489,7 @@ export function setProperty(node, key, prevValue, nextValue, isSvg, handlers) {
489489
} else {
490490
node.setAttribute(
491491
attr,
492-
isObject(nextValue) ? JSON.stringify(nextValue) : nextValue,
492+
isObject(nextValue) ? JSON.stringify(nextValue) : nextValue
493493
);
494494
}
495495
}

src/tests/render-internals.test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("src/render#setPropertyStyle", () => {
5858
setPropertyStyle(container.style, "--my-custom-property", "red");
5959

6060
expect(
61-
container.style.getPropertyValue("--my-custom-property"),
61+
container.style.getPropertyValue("--my-custom-property")
6262
).to.equal("red");
6363
});
6464
});
@@ -103,10 +103,12 @@ describe("src/render#setProperty", () => {
103103
container,
104104
"style",
105105
{ width: "0px" },
106-
{ width: "100px" },
106+
{
107+
width: "100px",
108+
},
107109
false,
108110
// @ts-ignore
109-
handlers,
111+
handlers
110112
);
111113

112114
expect(container.style.width).to.equal("100px");
@@ -129,7 +131,7 @@ describe("src/render#setProperty", () => {
129131
{ width: "0px" },
130132
{ width: "0px" },
131133
false,
132-
handlers,
134+
handlers
133135
);
134136

135137
expect(container.style.width).to.equal("");
@@ -159,7 +161,7 @@ describe("src/render#setProperty", () => {
159161
JSON.stringify(data),
160162
null,
161163
false,
162-
handlers,
164+
handlers
163165
);
164166

165167
expect(container.value).to.equal("");
@@ -180,7 +182,7 @@ describe("src/render#setProperty", () => {
180182
JSON.stringify(data),
181183
null,
182184
false,
183-
handlers,
185+
handlers
184186
);
185187

186188
expect(container.value).to.equal("");

src/utils.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const isNumber = (value) => typeof value == "number";
4242
* @param {any} value
4343
* @returns {value is TemplateStringsArray}
4444
*/
45-
export const isTagged = (value) => value && value.length > 0 && value.raw;
45+
export const isTagged = (value) => value && value.length && value.raw;
4646

4747
/**
4848
*
@@ -65,17 +65,16 @@ export function flat(list, callback) {
6565
let { length } = list;
6666
for (let i = 0; i < length; i++) {
6767
const value = list[i];
68-
if (value && Array.isArray(value)) {
68+
if (value && isArray(value)) {
6969
reduce(value);
7070
} else {
71-
const type = typeof value;
7271
if (
7372
value == null ||
74-
type === "function" ||
75-
type === "boolean"
73+
isFunction(value) ||
74+
typeof value === "boolean"
7675
) {
7776
continue;
78-
} else if (type === "string" || type === "number") {
77+
} else if (typeof value === "string" || isNumber(value)) {
7978
if (last == null) last = "";
8079
last += value;
8180
} else {

0 commit comments

Comments
 (0)