Skip to content

Commit f90f14e

Browse files
committed
[solid] Typings
1 parent ef33c15 commit f90f14e

25 files changed

Lines changed: 755 additions & 644 deletions

src/common/solid.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {isFunction, isUndefined} from './other.ts';
66

77
export type DependencyList = ReadonlyArray<unknown>;
88

9-
export const getValue = <Value>(value: Value | (() => Value)): Value =>
9+
export type MaybeAccessor<Value> = Value | (() => Value);
10+
11+
export const getValue = <Value>(value: MaybeAccessor<Value>): Value =>
1012
(isFunction(value) ? (value as () => Value)() : value) as Value;
1113

1214
export const getProps = <Props extends {[key: string]: any}>(

src/ui-solid/CellView.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
CellProps,
45
} from '../@types/ui-solid/index.d.ts';
56
import {getValue} from '../common/solid.ts';
67
import {EMPTY_STRING} from '../common/strings.ts';
7-
import {wrap} from './common/wrap.tsx';
8+
import {renderView, wrap} from './common/wrap.tsx';
89
import {useCell} from './hooks.ts';
910

10-
export const CellView = (props: CellProps): any => {
11+
export const CellView = (props: CellProps): JSXElement => {
1112
const cell = useCell(
12-
(() => props.tableId) as any,
13-
(() => props.rowId) as any,
14-
(() => props.cellId) as any,
15-
(() => props.store) as any,
16-
) as any;
17-
return () =>
13+
() => props.tableId,
14+
() => props.rowId,
15+
() => props.cellId,
16+
() => props.store,
17+
);
18+
return renderView(() =>
1819
wrap(
19-
EMPTY_STRING + ((getValue(cell) as any) ?? EMPTY_STRING),
20+
EMPTY_STRING + (getValue(cell) ?? EMPTY_STRING),
2021
undefined,
2122
props.debugIds,
2223
props.cellId,
23-
);
24+
),
25+
);
2426
};

src/ui-solid/CheckpointView.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
CheckpointProps,
45
} from '../@types/ui-solid/index.d.ts';
56
import {getValue} from '../common/solid.ts';
67
import {EMPTY_STRING} from '../common/strings.ts';
7-
import {wrap} from './common/wrap.tsx';
8+
import {renderView, wrap} from './common/wrap.tsx';
89
import {useCheckpoint} from './hooks.ts';
910

10-
export const CheckpointView = (props: CheckpointProps): any => {
11+
export const CheckpointView = (props: CheckpointProps): JSXElement => {
1112
const checkpoint = useCheckpoint(
12-
(() => props.checkpointId) as any,
13-
(() => props.checkpoints) as any,
14-
) as any;
15-
return () =>
13+
() => props.checkpointId,
14+
() => props.checkpoints,
15+
);
16+
return renderView(() =>
1617
wrap(
17-
(getValue(checkpoint) as any) ?? EMPTY_STRING,
18+
getValue(checkpoint) ?? EMPTY_STRING,
1819
undefined,
1920
props.debugIds,
2021
props.checkpointId,
21-
);
22+
),
23+
);
2224
};

src/ui-solid/IndexView.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
IndexProps,
45
} from '../@types/ui-solid/index.d.ts';
56
import type {Id} from '../@types/index.d.ts';
67
import {arrayMap} from '../common/array.ts';
78
import {getProps, getValue} from '../common/solid.ts';
8-
import {wrap} from './common/wrap.tsx';
9+
import {renderView, wrap} from './common/wrap.tsx';
910
import {useSliceIds} from './hooks.ts';
1011
import {SliceView} from './SliceView.tsx';
1112

12-
export const IndexView = (props: IndexProps): any => {
13+
export const IndexView = (props: IndexProps): JSXElement => {
1314
const sliceIds = useSliceIds(
14-
(() => props.indexId) as any,
15-
(() => props.indexes) as any,
16-
) as any;
17-
return () => {
15+
() => props.indexId,
16+
() => props.indexes,
17+
);
18+
return renderView(() => {
1819
const Slice = props.sliceComponent ?? SliceView;
1920
return wrap(
2021
arrayMap(getValue(sliceIds) as Id[], (sliceId: Id) => (
@@ -30,5 +31,5 @@ export const IndexView = (props: IndexProps): any => {
3031
props.debugIds,
3132
props.indexId,
3233
);
33-
};
34+
});
3435
};

src/ui-solid/LinkedRowsView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
LinkedRowsProps,
45
} from '../@types/ui-solid/index.d.ts';
@@ -7,5 +8,5 @@ import {useLinkedRowIds} from './hooks.ts';
78

89
export const LinkedRowsView = (
910
props: LinkedRowsProps,
10-
): any =>
11-
useComponentPerRow(props as any, useLinkedRowIds as any, () => props.firstRowId);
11+
): JSXElement =>
12+
useComponentPerRow(props, useLinkedRowIds, () => props.firstRowId);

src/ui-solid/LocalRowsView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
LocalRowsProps,
45
} from '../@types/ui-solid/index.d.ts';
@@ -7,5 +8,5 @@ import {useLocalRowIds} from './hooks.ts';
78

89
export const LocalRowsView = (
910
props: LocalRowsProps,
10-
): any =>
11-
useComponentPerRow(props as any, useLocalRowIds as any, () => props.remoteRowId);
11+
): JSXElement =>
12+
useComponentPerRow(props, useLocalRowIds, () => props.remoteRowId);

src/ui-solid/MetricView.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
MetricProps,
45
} from '../@types/ui-solid/index.d.ts';
56
import {getValue} from '../common/solid.ts';
67
import {EMPTY_STRING} from '../common/strings.ts';
7-
import {wrap} from './common/wrap.tsx';
8+
import {renderView, wrap} from './common/wrap.tsx';
89
import {useMetric} from './hooks.ts';
910

10-
export const MetricView = (props: MetricProps): any => {
11+
export const MetricView = (props: MetricProps): JSXElement => {
1112
const metric = useMetric(
12-
(() => props.metricId) as any,
13-
(() => props.metrics) as any,
14-
) as any;
15-
return () =>
13+
() => props.metricId,
14+
() => props.metrics,
15+
);
16+
return renderView(() =>
1617
wrap(
17-
(getValue(metric) as any) ?? EMPTY_STRING,
18+
getValue(metric) ?? EMPTY_STRING,
1819
undefined,
1920
props.debugIds,
2021
props.metricId,
21-
);
22+
),
23+
);
2224
};

src/ui-solid/Provider.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {createMemo, createSignal, useContext} from 'solid-js';
44
import type {Id} from '../@types/index.d.ts';
55
import type {ProviderProps} from '../@types/ui-solid/index.d.ts';
66
import {arrayNew, arrayWith} from '../common/array.ts';
7-
import {objDel, objGet, objHas} from '../common/obj.ts';
7+
import {IdObj, objDel, objGet, objHas} from '../common/obj.ts';
88
import {ExtraThingsById, ThingsById} from './common/index.tsx';
99
import {Context, ContextValue, ThingsByOffset} from './context.ts';
1010

@@ -47,7 +47,7 @@ const EMPTY_CONTEXT = () => [] as ContextValue;
4747

4848
export const Provider = (
4949
props: ProviderProps & {readonly children: JSXElement},
50-
): any => {
50+
): JSXElement => {
5151
const parentValue =
5252
useContext(Context) ?? (EMPTY_CONTEXT as Accessor<ContextValue>);
5353
const [extraThingsById, setExtraThingsById] = createSignal<ExtraThingsById>(
@@ -60,12 +60,17 @@ export const Provider = (
6060
thing: ThingsByOffset[Offset],
6161
): void => {
6262
setExtraThingsById((extraThingsById) =>
63-
objGet(extraThingsById[thingOffset] as any, id) == thing
63+
objGet(
64+
extraThingsById[thingOffset] as IdObj<ThingsByOffset[Offset]>,
65+
id,
66+
) == thing
6467
? extraThingsById
6568
: (arrayWith(extraThingsById, thingOffset, {
66-
...extraThingsById[thingOffset],
69+
...(extraThingsById[thingOffset] as IdObj<
70+
ThingsByOffset[Offset]
71+
>),
6772
[id]: thing,
68-
} as any) as ExtraThingsById),
73+
} as ThingsById<ThingsByOffset>[Offset]) as ExtraThingsById),
6974
);
7075
};
7176

@@ -76,7 +81,12 @@ export const Provider = (
7681
: (arrayWith(
7782
extraThingsById,
7883
thingOffset,
79-
objDel(extraThingsById[thingOffset] as any, id),
84+
objDel(
85+
extraThingsById[thingOffset] as IdObj<
86+
ThingsByOffset[typeof thingOffset]
87+
>,
88+
id,
89+
),
8090
) as ExtraThingsById),
8191
);
8292
};

src/ui-solid/RemoteRowView.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {Id} from '../@types/index.d.ts';
34
import type {
45
RemoteRowProps,
@@ -9,23 +10,23 @@ import {
910
getRelationshipsStoreTableIds,
1011
getValue,
1112
} from '../common/solid.ts';
12-
import {wrap} from './common/wrap.tsx';
13+
import {renderView, wrap} from './common/wrap.tsx';
1314
import {useRelationshipsOrRelationshipsById, useRemoteRowId} from './hooks.ts';
1415
import {RowView} from './RowView.tsx';
1516

16-
export const RemoteRowView = (props: RemoteRowProps): any => {
17+
export const RemoteRowView = (props: RemoteRowProps): JSXElement => {
1718
const resolvedRelationships =
18-
useRelationshipsOrRelationshipsById((() => props.relationships) as any);
19+
useRelationshipsOrRelationshipsById(() => props.relationships);
1920
const rowId = useRemoteRowId(
20-
(() => props.relationshipId) as any,
21-
(() => props.localRowId) as any,
22-
resolvedRelationships as any,
23-
) as any;
24-
return () => {
21+
() => props.relationshipId,
22+
() => props.localRowId,
23+
resolvedRelationships,
24+
);
25+
return renderView(() => {
2526
const Row = props.rowComponent ?? RowView;
2627
const [_relationshipsValue, store, , remoteTableId] =
2728
getRelationshipsStoreTableIds(
28-
getValue(resolvedRelationships as any),
29+
getValue(resolvedRelationships),
2930
props.relationshipId,
3031
);
3132
const remoteRowId = getValue(rowId) as Id | undefined;
@@ -43,5 +44,5 @@ export const RemoteRowView = (props: RemoteRowProps): any => {
4344
props.debugIds,
4445
props.localRowId,
4546
);
46-
};
47+
});
4748
};

src/ui-solid/ResultCellView.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
/* @jsxImportSource solid-js */
2+
import type {JSXElement} from 'solid-js';
23
import type {
34
ResultCellProps,
45
} from '../@types/ui-solid/index.d.ts';
56
import {getValue} from '../common/solid.ts';
67
import {EMPTY_STRING} from '../common/strings.ts';
7-
import {wrap} from './common/wrap.tsx';
8+
import {renderView, wrap} from './common/wrap.tsx';
89
import {useResultCell} from './hooks.ts';
910

10-
export const ResultCellView = (props: ResultCellProps): any => {
11+
export const ResultCellView = (props: ResultCellProps): JSXElement => {
1112
const resultCell = useResultCell(
12-
(() => props.queryId) as any,
13-
(() => props.rowId) as any,
14-
(() => props.cellId) as any,
15-
(() => props.queries) as any,
16-
) as any;
17-
return () =>
13+
() => props.queryId,
14+
() => props.rowId,
15+
() => props.cellId,
16+
() => props.queries,
17+
);
18+
return renderView(() =>
1819
wrap(
19-
EMPTY_STRING + ((getValue(resultCell) as any) ?? EMPTY_STRING),
20+
EMPTY_STRING + (getValue(resultCell) ?? EMPTY_STRING),
2021
undefined,
2122
props.debugIds,
2223
props.cellId,
23-
);
24+
),
25+
);
2426
};

0 commit comments

Comments
 (0)