Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 24c0953

Browse files
committed
ui/react: extract types from hooks
1 parent 07513f8 commit 24c0953

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/ui/react/hooks/index.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
11
import type { DebugConfig, FullDB } from "../../../core";
22
import type { ReactType } from "../types";
3+
import type {
4+
Changer,
5+
MassUpdater,
6+
MassUpdaterInternal,
7+
Updater,
8+
UpdaterInternal,
9+
} from "./types";
10+
11+
export type { MassUpdater, Updater } from "./types";
312

413
function flat<T>(list: T[][]): T[] {
514
return list.reduce((a, b) => a.concat(b));
615
}
716

8-
type MassUpdaterInternal<Domain, K extends keyof Domain> = (
9-
options: {},
10-
kind: K,
11-
id: string,
12-
delta: (prev: Domain[K]) => Domain[K]
13-
) => void;
14-
export type MassUpdater<Domain, K extends keyof Domain> = MassUpdaterInternal<
15-
Domain,
16-
K
17-
> & {
18-
(kind: K, id: string, delta: (prev: Domain[K]) => Domain[K]): void;
19-
};
20-
21-
type UpdaterInternal<T> = (options: {}, delta: (prev: T) => T) => void;
22-
export type Updater<T> = UpdaterInternal<T> & {
23-
(delta: (prev: T) => T): void;
24-
} & (T extends {}
25-
? { <K extends keyof T & string>(field: K, value: T[K]): void }
26-
: {});
27-
type Changer<T> = [T | "loading", Updater<T>];
28-
2917
function makeMassUpdater<Domain, K extends keyof Domain>(
3018
db: FullDB<Domain>
3119
): MassUpdater<Domain, K> {

src/ui/react/hooks/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type MassUpdaterInternal<Domain, K extends keyof Domain> = (
2+
options: {},
3+
kind: K,
4+
id: string,
5+
delta: (prev: Domain[K]) => Domain[K]
6+
) => void;
7+
export type MassUpdater<Domain, K extends keyof Domain> = MassUpdaterInternal<
8+
Domain,
9+
K
10+
> & {
11+
(kind: K, id: string, delta: (prev: Domain[K]) => Domain[K]): void;
12+
};
13+
14+
export type UpdaterInternal<T> = (options: {}, delta: (prev: T) => T) => void;
15+
export type Updater<T> = UpdaterInternal<T> & {
16+
(delta: (prev: T) => T): void;
17+
} & (T extends {}
18+
? { <K extends keyof T & string>(field: K, value: T[K]): void }
19+
: {});
20+
export type Changer<T> = [T | "loading", Updater<T>];

0 commit comments

Comments
 (0)