Skip to content

Commit

Permalink
prettier is dog-shit
Browse files Browse the repository at this point in the history
  • Loading branch information
TGlide committed Apr 22, 2024
1 parent f275445 commit 833e433
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never",
"source.organizeImports": "never"
},
"editor.formatOnSave": true,
// Enable eslint for all supported languages
Expand All @@ -22,5 +22,5 @@
"yaml",
"toml",
"astro"
],
}
]
}
4 changes: 1 addition & 3 deletions packages/runed/src/lib/functions/box/box.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


import { type ReadonlyBox, isReadonlyBox } from '../readonlyBox/readonlyBox.svelte.js';
import { type ReadonlyBox, isReadonlyBox } from "../readonlyBox/readonlyBox.svelte.js";
import type { Getter, Setter } from "$lib/internal/types.js";
import { isFunction, isObject } from "$lib/internal/utils/is.js";

Expand Down
38 changes: 22 additions & 16 deletions packages/runed/src/lib/functions/box/box.test.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,84 @@ describe("box", () => {
expect(count.value).toBe(0);
count.value = 1;
expect(count.value).toBe(1);
})
});

test("box with getter only should throw", () => {
expect(() => box(() => 0)).toThrow();
})
});

test("box with initial value and setter should be settable", () => {
const count = box(0, (c) => c);
expect(count.value).toBe(0);
count.value = 1;
expect(count.value).toBe(1);
})
});

test("box with getter and setter should be settable", () => {
let count = $state(0);
const countBox = box(() => count, (c) => count = c);
const countBox = box(
() => count,
(c) => (count = c)
);
expect(countBox.value).toBe(0);
countBox.value = 1;
expect(countBox.value).toBe(1);
})
});

test("box of readonly box should throw", () => {
expect(() => box(readonlyBox(() => 0))).toThrow();
})
});

test("box of box should be settable", () => {
const count = box(box(0));
expect(count.value).toBe(0);
count.value = 1;
expect(count.value).toBe(1);
})
})
});
});

describe("box types", () => {
test("box with initial value", () => {
const count = box(0);
expectTypeOf(count).toMatchTypeOf<Box<number>>();
expectTypeOf(count).not.toMatchTypeOf<ReadonlyBox<number>>();
})
});

test("box with getter only", () => {
const count = box(0 as unknown as Getter<number>);
expectTypeOf(count).toMatchTypeOf<never>();
})
});

test("box with initial value and setter", () => {
const count = box(0, (c) => c);
expectTypeOf(count).toMatchTypeOf<Box<number>>();
expectTypeOf(count).not.toMatchTypeOf<ReadonlyBox<number>>();
})
});

test("box with getter and setter", () => {
let count = $state(0);
const countBox = box(() => count, (c) => count = c);
const countBox = box(
() => count,
(c) => (count = c)
);
expectTypeOf(countBox).toMatchTypeOf<Box<number>>();
expectTypeOf(countBox).not.toMatchTypeOf<ReadonlyBox<number>>();
})
});

test("box of readonly box", () => {
const count = box(0 as unknown as ReadonlyBox<number>);
expectTypeOf(count).toMatchTypeOf<never>();
})
});

test("box of box", () => {
const count = box(box(0));
expectTypeOf(count).toMatchTypeOf<Box<number>>();
expectTypeOf(count).not.toMatchTypeOf<ReadonlyBox<number>>();
})
});

test("box of ValueOrBox", () => {
const count = undefined as unknown as ValueOrBox<number>; // typing this as number casts it
const readonlyCount = box(count);
expectTypeOf(readonlyCount).toMatchTypeOf<Box<number>>;
});
})
});
2 changes: 1 addition & 1 deletion packages/runed/src/lib/functions/box/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './box.svelte.js'
export * from "./box.svelte.js";
4 changes: 2 additions & 2 deletions packages/runed/src/lib/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export * from "./useActiveElement/index.js";
export * from "./useDebounce/index.js";
export * from "./useElementSize/index.js";
export * from "./useEventListener/index.js";
export * from "./box/index.js"
export * from "./readonlyBox/index.js"
export * from "./box/index.js";
export * from "./readonlyBox/index.js";
2 changes: 1 addition & 1 deletion packages/runed/src/lib/functions/readonlyBox/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './readonlyBox.svelte.js'
export * from "./readonlyBox.svelte.js";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Box, isBox } from "../box/box.svelte.js";
import { isFunction, isObject } from "$lib/internal/utils/is.js";
import type { Getter, } from "$lib/internal/types.js";
import type { Getter } from "$lib/internal/types.js";

const ReadonlyBoxSymbol = Symbol("ReadonlyBox");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import type { ValueOrReadonlyBox } from "$lib/index.js";
import { readonlyBox } from "$lib/index.js";


type Options = {
initialSize?: {
width: number;
Expand Down
5 changes: 1 addition & 4 deletions packages/runed/src/lib/internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { ReadonlyBox } from "$lib/functions/index.js";


// eslint-disable-next-line ts/no-explicit-any
export type FunctionArgs<Args extends any[] = any[], Return = void> = (...args: Args) => Return;

export type Getter<T> = () => T;
export type ValueOrGetter<T> = T | (() => T);

export type Setter<T> = (value: T) => void | T;
export type Setter<T> = (value: T) => void | T;
2 changes: 1 addition & 1 deletion packages/runed/src/lib/internal/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export function isFunction(value: unknown): value is (...args: unknown[]) => unk

export function isObject(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === "object";
}
}

0 comments on commit 833e433

Please sign in to comment.