Skip to content

Commit

Permalink
fix: use string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 22, 2021
1 parent 63ff8d1 commit 0da27c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: Ow
? UNOWNED
: { owned: null, cleanups: null, context: null, owner, attached: Boolean(detachedOwner) };

if ("_SOLID_DEV_" && owner) root.name = (owner as Computation<any>).name + "-r" + rootCount++;
if ("_SOLID_DEV_" && owner) root.name = `${(owner as Computation<any>).name}-r${rootCount++}`;
Owner = root;
Listener = null;
let result: T;
Expand Down Expand Up @@ -585,8 +585,8 @@ export function devComponent<T>(Comp: (props: T) => JSX.Element, props: T) {
export function hashValue(v: any): string {
const s = new Set();
return (
"s" +
(typeof v === "string"
`s${
typeof v === "string"
? hash(v)
: hash(
JSON.stringify(v, (k, v) => {
Expand All @@ -596,7 +596,7 @@ export function hashValue(v: any): string {
}
return v;
}) || ""
))
)}`
);
}

Expand All @@ -605,7 +605,7 @@ export function registerGraph(name: string, value: { value: unknown }): string {
if (Owner) {
let i = 0;
Owner.sourceMap || (Owner.sourceMap = {});
while (Owner.sourceMap[tryName]) tryName = name + "-" + ++i;
while (Owner.sourceMap[tryName]) tryName = `${name}-${++i}`;
Owner.sourceMap[tryName] = value;
}
return tryName;
Expand Down Expand Up @@ -804,9 +804,9 @@ function createComputation<T>(
if ("_SOLID_DEV_")
c.name =
(options && options.name) ||
((Owner as Computation<any>).name || "c") +
"-" +
(Owner.owned || (Owner as Memo<T>).tOwned!).length;
`${(Owner as Computation<any>).name || "c"}-${
(Owner.owned || (Owner as Memo<T>).tOwned!).length
}`;
}
return c;
}
Expand Down
20 changes: 10 additions & 10 deletions packages/solid/test/signals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("Create signals", () => {
});
test("Create and read a Memo with initial value", () => {
createRoot(() => {
const memo = createMemo(i => i + " John", "Hello");
const memo = createMemo(i => `${i} John`, "Hello");
expect(memo()).toBe("Hello John");
});
});
Expand All @@ -51,7 +51,7 @@ describe("Create signals", () => {
createRoot(() => {
let temp: string;
const [sign] = createSignal("thoughts");
createComputed(on(sign, v => (temp = "impure " + v)));
createComputed(on(sign, v => (temp = `impure ${v}`)));
expect(temp!).toBe("impure thoughts");
});
});
Expand All @@ -60,15 +60,15 @@ describe("Create signals", () => {
let temp: string;
const [sign] = createSignal("thoughts");
const [num] = createSignal(3);
createComputed(on([sign, num], v => (temp = "impure " + v[1])));
createComputed(on([sign, num], v => (temp = `impure ${v[1]}`)));
expect(temp!).toBe("impure 3");
});
});
test("Create a Computed with explicit deps and lazy evaluation", () => {
createRoot(() => {
let temp: string;
const [sign, set] = createSignal("thoughts");
createComputed(on(sign, v => (temp = "impure " + v), { defer: true }));
createComputed(on(sign, v => (temp = `impure ${v}`), { defer: true }));
expect(temp!).toBeUndefined();
set("minds");
expect(temp!).toBe("impure minds");
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("Update signals", () => {
test("Create and trigger a Memo", () => {
createRoot(() => {
const [name, setName] = createSignal("John"),
memo = createMemo(() => "Hello " + name());
memo = createMemo(() => `Hello ${name()}`);
expect(memo()).toBe("Hello John");
setName("Jake");
expect(memo()).toBe("Hello Jake");
Expand All @@ -110,8 +110,8 @@ describe("Update signals", () => {
createRoot(() => {
let temp: string;
const [name, setName] = createSignal("John"),
memo = createMemo(() => "Hello " + name());
createEffect(() => (temp = memo() + "!!!"));
memo = createMemo(() => `Hello ${name()}`);
createEffect(() => (temp = `${memo()}!!!`));
setTimeout(() => {
expect(temp).toBe("Hello John!!!");
setName("Jake");
Expand All @@ -124,7 +124,7 @@ describe("Update signals", () => {
createRoot(() => {
let temp: string;
const [sign, setSign] = createSignal("thoughts");
createEffect(() => (temp = "unpure " + sign()));
createEffect(() => (temp = `unpure ${sign()}`));
setTimeout(() => {
expect(temp).toBe("unpure thoughts");
setSign("mind");
Expand All @@ -151,7 +151,7 @@ describe("Untrack signals", () => {
createRoot(() => {
let temp: string;
const [sign, setSign] = createSignal("thoughts");
createEffect(() => (temp = "unpure " + untrack(sign)));
createEffect(() => (temp = `unpure ${untrack(sign)}`));
setTimeout(() => {
expect(temp).toBe("unpure thoughts");
setSign("mind");
Expand Down Expand Up @@ -240,7 +240,7 @@ describe("Batch signals", () => {
expect(count).toBe(2);
done();
});
})
});
});
});
test("Handles errors gracefully", done => {
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/web/test/for.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("Testing an multi child each control flow", () => {

function apply(array: string[]) {
setList(array);
expect(div.innerHTML).toBe(array.join("") + "z");
expect(div.innerHTML).toBe(`${array.join("")}z`);
setList([n1, n2, n3, n4]);
expect(div.innerHTML).toBe("abcdz");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/web/test/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("Testing an multi child each control flow", () => {

function apply(array: string[]) {
setList(array);
expect(div.innerHTML).toBe(array.join("") + "z");
expect(div.innerHTML).toBe(`${array.join("")}z`);
setList([n1, n2, n3, n4]);
expect(div.innerHTML).toBe("abcdz");
}
Expand Down

0 comments on commit 0da27c8

Please sign in to comment.