Skip to content

Commit f5efff8

Browse files
committed
[hygiene] Remove offset enum
1 parent 9f97cc9 commit f5efff8

File tree

4 files changed

+73
-65
lines changed

4 files changed

+73
-65
lines changed

src/ui-react/Provider.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,28 @@ import type {
77
import {arrayNew, arrayWith} from '../common/array.ts';
88
import {objDel, objGet, objHas} from '../common/obj.ts';
99
import {useCallback, useContext, useMemo, useState} from '../common/react.ts';
10-
import {ExtraThingsById, Offsets, mergeParentThings} from './common.tsx';
10+
import {ExtraThingsById, mergeParentThings} from './common.tsx';
1111
import {Context, ThingsByOffset} from './context.ts';
1212

13+
export type Offsets =
14+
| typeof OFFSET_STORE
15+
| typeof OFFSET_METRICS
16+
| typeof OFFSET_INDEXES
17+
| typeof OFFSET_RELATIONSHIPS
18+
| typeof OFFSET_QUERIES
19+
| typeof OFFSET_CHECKPOINTS
20+
| typeof OFFSET_PERSISTER
21+
| typeof OFFSET_SYNCHRONIZER;
22+
23+
export const OFFSET_STORE = 0;
24+
export const OFFSET_METRICS = 1;
25+
export const OFFSET_INDEXES = 2;
26+
export const OFFSET_RELATIONSHIPS = 3;
27+
export const OFFSET_QUERIES = 4;
28+
export const OFFSET_CHECKPOINTS = 5;
29+
export const OFFSET_PERSISTER = 6;
30+
export const OFFSET_SYNCHRONIZER = 7;
31+
1332
export const Provider: typeof ProviderDecl = ({
1433
store,
1534
storesById,
@@ -69,56 +88,56 @@ export const Provider: typeof ProviderDecl = ({
6988
value={useMemo(
7089
() => [
7190
...mergeParentThings(
72-
Offsets.Store,
91+
OFFSET_STORE,
7392
parentValue,
7493
store,
7594
storesById,
7695
extraThingsById,
7796
),
7897
...mergeParentThings(
79-
Offsets.Metrics,
98+
OFFSET_METRICS,
8099
parentValue,
81100
metrics,
82101
metricsById,
83102
extraThingsById,
84103
),
85104
...mergeParentThings(
86-
Offsets.Indexes,
105+
OFFSET_INDEXES,
87106
parentValue,
88107
indexes,
89108
indexesById,
90109
extraThingsById,
91110
),
92111
...mergeParentThings(
93-
Offsets.Relationships,
112+
OFFSET_RELATIONSHIPS,
94113
parentValue,
95114
relationships,
96115
relationshipsById,
97116
extraThingsById,
98117
),
99118
...mergeParentThings(
100-
Offsets.Queries,
119+
OFFSET_QUERIES,
101120
parentValue,
102121
queries,
103122
queriesById,
104123
extraThingsById,
105124
),
106125
...mergeParentThings(
107-
Offsets.Checkpoints,
126+
OFFSET_CHECKPOINTS,
108127
parentValue,
109128
checkpoints,
110129
checkpointsById,
111130
extraThingsById,
112131
),
113132
...mergeParentThings(
114-
Offsets.Persister,
133+
OFFSET_PERSISTER,
115134
parentValue,
116135
persister,
117136
persistersById,
118137
extraThingsById,
119138
),
120139
...mergeParentThings(
121-
Offsets.Synchronizer,
140+
OFFSET_SYNCHRONIZER,
122141
parentValue,
123142
synchronizer,
124143
synchronizersById,

src/ui-react/common.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,10 @@ import {
2424
useCheckpointsOrCheckpointsById,
2525
useRelationshipsOrRelationshipsById,
2626
} from './hooks.ts';
27+
import type {Offsets} from './Provider.tsx';
2728
import {ResultRowView} from './ResultRowView.tsx';
2829
import {RowView} from './RowView.tsx';
2930

30-
export enum Offsets {
31-
Store = 0,
32-
Metrics = 1,
33-
Indexes = 2,
34-
Relationships = 3,
35-
Queries = 4,
36-
Checkpoints = 5,
37-
Persister = 6,
38-
Synchronizer = 7,
39-
}
40-
4131
type ThingsById<ThingsByOffset> = {
4232
[Offset in keyof ThingsByOffset]: {[id: Id]: ThingsByOffset[Offset]};
4333
};

src/ui-react/context.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {IdObj, objGet, objIds} from '../common/obj.ts';
1212
import {GLOBAL, isString, isUndefined} from '../common/other.ts';
1313
import {createContext, useContext, useEffect} from '../common/react.ts';
1414
import {TINYBASE} from '../common/strings.ts';
15+
import type {Offsets} from './Provider.tsx';
1516

1617
export type Thing =
1718
| Store
@@ -34,17 +35,6 @@ export type ThingsByOffset = [
3435
Synchronizer,
3536
];
3637

37-
export enum Offsets {
38-
Store = 0,
39-
Metrics = 1,
40-
Indexes = 2,
41-
Relationships = 3,
42-
Queries = 4,
43-
Checkpoints = 5,
44-
Persister = 6,
45-
Synchronizer = 7,
46-
}
47-
4838
export type ContextValue = [
4939
store?: Store,
5040
storesById?: {[storeId: Id]: Store},

src/ui-react/hooks.ts

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,22 @@ import {
297297
_HAS,
298298
} from '../common/strings.ts';
299299
import {
300-
Offsets,
301300
useProvideThing,
302301
useThing,
303302
useThingIds,
304303
useThingOrThingById,
305304
useThings,
306305
} from './context.ts';
306+
import {
307+
OFFSET_CHECKPOINTS,
308+
OFFSET_INDEXES,
309+
OFFSET_METRICS,
310+
OFFSET_PERSISTER,
311+
OFFSET_QUERIES,
312+
OFFSET_RELATIONSHIPS,
313+
OFFSET_STORE,
314+
OFFSET_SYNCHRONIZER,
315+
} from './Provider.tsx';
307316

308317
const EMPTY_ARRAY: Readonly<[]> = [];
309318

@@ -525,22 +534,22 @@ export const useCreateStore: typeof useCreateStoreDecl = (
525534
): Store => useMemo(create, createDeps);
526535

527536
export const useStoreIds: typeof useStoreIdsDecl = () =>
528-
useThingIds(Offsets.Store);
537+
useThingIds(OFFSET_STORE);
529538

530539
export const useStore: typeof useStoreDecl = (id?: Id): Store | undefined =>
531-
useThing(id, Offsets.Store);
540+
useThing(id, OFFSET_STORE);
532541

533542
export const useStores: typeof useStoresDecl = (): IdObj<Store> =>
534-
useThings(Offsets.Store);
543+
useThings(OFFSET_STORE);
535544

536545
export const useStoreOrStoreById: typeof useStoreOrStoreByIdDecl = (
537546
storeOrStoreId?: StoreOrStoreId,
538-
): Store | undefined => useThingOrThingById(storeOrStoreId, Offsets.Store);
547+
): Store | undefined => useThingOrThingById(storeOrStoreId, OFFSET_STORE);
539548

540549
export const useProvideStore: typeof useProvideStoreDecl = (
541550
storeId: Id,
542551
store: Store,
543-
): void => useProvideThing(storeId, store, Offsets.Store);
552+
): void => useProvideThing(storeId, store, OFFSET_STORE);
544553

545554
export const useCreateMergeableStore: typeof useCreateMergeableStoreDecl = (
546555
create: () => MergeableStore,
@@ -1396,21 +1405,21 @@ export const useCreateMetrics: typeof useCreateMetricsDecl = (
13961405
): Metrics | undefined => useCreate(store, create, createDeps);
13971406

13981407
export const useMetricsIds: typeof useMetricsIdsDecl = () =>
1399-
useThingIds(Offsets.Metrics);
1408+
useThingIds(OFFSET_METRICS);
14001409

14011410
export const useMetrics: typeof useMetricsDecl = (
14021411
id?: Id,
1403-
): Metrics | undefined => useThing(id, Offsets.Metrics);
1412+
): Metrics | undefined => useThing(id, OFFSET_METRICS);
14041413

14051414
export const useMetricsOrMetricsById: typeof useMetricsOrMetricsByIdDecl = (
14061415
metricsOrMetricsId?: MetricsOrMetricsId,
14071416
): Metrics | undefined =>
1408-
useThingOrThingById(metricsOrMetricsId, Offsets.Metrics);
1417+
useThingOrThingById(metricsOrMetricsId, OFFSET_METRICS);
14091418

14101419
export const useProvideMetrics: typeof useProvideMetricsDecl = (
14111420
metricsId: Id,
14121421
metrics: Metrics,
1413-
): void => useProvideThing(metricsId, metrics, Offsets.Metrics);
1422+
): void => useProvideThing(metricsId, metrics, OFFSET_METRICS);
14141423

14151424
export const useMetricIds: typeof useMetricIdsDecl = (
14161425
metricsOrMetricsId?: MetricsOrMetricsId,
@@ -1453,21 +1462,21 @@ export const useCreateIndexes: typeof useCreateIndexesDecl = (
14531462
): Indexes | undefined => useCreate(store, create, createDeps);
14541463

14551464
export const useIndexesIds: typeof useIndexesIdsDecl = () =>
1456-
useThingIds(Offsets.Indexes);
1465+
useThingIds(OFFSET_INDEXES);
14571466

14581467
export const useIndexes: typeof useIndexesDecl = (
14591468
id?: Id,
1460-
): Indexes | undefined => useThing(id, Offsets.Indexes);
1469+
): Indexes | undefined => useThing(id, OFFSET_INDEXES);
14611470

14621471
export const useIndexesOrIndexesById: typeof useIndexesOrIndexesByIdDecl = (
14631472
indexesOrIndexesId?: IndexesOrIndexesId,
14641473
): Indexes | undefined =>
1465-
useThingOrThingById(indexesOrIndexesId, Offsets.Indexes);
1474+
useThingOrThingById(indexesOrIndexesId, OFFSET_INDEXES);
14661475

14671476
export const useProvideIndexes: typeof useProvideIndexesDecl = (
14681477
indexesId: Id,
14691478
indexes: Indexes,
1470-
): void => useProvideThing(indexesId, indexes, Offsets.Indexes);
1479+
): void => useProvideThing(indexesId, indexes, OFFSET_INDEXES);
14711480

14721481
export const useSliceIds: typeof useSliceIdsDecl = (
14731482
indexId: Id,
@@ -1537,23 +1546,23 @@ export const useCreateRelationships: typeof useCreateRelationshipsDecl = (
15371546
): Relationships | undefined => useCreate(store, create, createDeps);
15381547

15391548
export const useRelationshipsIds: typeof useRelationshipsIdsDecl = () =>
1540-
useThingIds(Offsets.Relationships);
1549+
useThingIds(OFFSET_RELATIONSHIPS);
15411550

15421551
export const useRelationships: typeof useRelationshipsDecl = (
15431552
id?: Id,
1544-
): Relationships | undefined => useThing(id, Offsets.Relationships);
1553+
): Relationships | undefined => useThing(id, OFFSET_RELATIONSHIPS);
15451554

15461555
export const useRelationshipsOrRelationshipsById: typeof useRelationshipsOrRelationshipsByIdDecl =
15471556
(
15481557
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
15491558
): Relationships | undefined =>
1550-
useThingOrThingById(relationshipsOrRelationshipsId, Offsets.Relationships);
1559+
useThingOrThingById(relationshipsOrRelationshipsId, OFFSET_RELATIONSHIPS);
15511560

15521561
export const useProvideRelationships: typeof useProvideRelationshipsDecl = (
15531562
relationshipsId: Id,
15541563
relationships: Relationships,
15551564
): void =>
1556-
useProvideThing(relationshipsId, relationships, Offsets.Relationships);
1565+
useProvideThing(relationshipsId, relationships, OFFSET_RELATIONSHIPS);
15571566

15581567
export const useRelationshipIds: typeof useRelationshipIdsDecl = (
15591568
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
@@ -1652,21 +1661,21 @@ export const useCreateQueries: typeof useCreateQueriesDecl = (
16521661
): Queries | undefined => useCreate(store, create, createDeps);
16531662

16541663
export const useQueriesIds: typeof useQueriesIdsDecl = () =>
1655-
useThingIds(Offsets.Queries);
1664+
useThingIds(OFFSET_QUERIES);
16561665

16571666
export const useQueries: typeof useQueriesDecl = (
16581667
id?: Id,
1659-
): Queries | undefined => useThing(id, Offsets.Queries);
1668+
): Queries | undefined => useThing(id, OFFSET_QUERIES);
16601669

16611670
export const useQueriesOrQueriesById: typeof useQueriesOrQueriesByIdDecl = (
16621671
queriesOrQueriesId?: QueriesOrQueriesId,
16631672
): Queries | undefined =>
1664-
useThingOrThingById(queriesOrQueriesId, Offsets.Queries);
1673+
useThingOrThingById(queriesOrQueriesId, OFFSET_QUERIES);
16651674

16661675
export const useProvideQueries: typeof useProvideQueriesDecl = (
16671676
queriesId: Id,
16681677
queries: Queries,
1669-
): void => useProvideThing(queriesId, queries, Offsets.Queries);
1678+
): void => useProvideThing(queriesId, queries, OFFSET_QUERIES);
16701679

16711680
export const useQueryIds: typeof useQueryIdsDecl = (
16721681
queriesOrQueriesId?: QueriesOrQueriesId,
@@ -1902,22 +1911,22 @@ export const useCreateCheckpoints: typeof useCreateCheckpointsDecl = (
19021911
): Checkpoints | undefined => useCreate(store, create, createDeps);
19031912

19041913
export const useCheckpointsIds: typeof useCheckpointsIdsDecl = () =>
1905-
useThingIds(Offsets.Checkpoints);
1914+
useThingIds(OFFSET_CHECKPOINTS);
19061915

19071916
export const useCheckpoints: typeof useCheckpointsDecl = (
19081917
id?: Id,
1909-
): Checkpoints | undefined => useThing(id, Offsets.Checkpoints);
1918+
): Checkpoints | undefined => useThing(id, OFFSET_CHECKPOINTS);
19101919

19111920
export const useCheckpointsOrCheckpointsById: typeof useCheckpointsOrCheckpointsByIdDecl =
19121921
(
19131922
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
19141923
): Checkpoints | undefined =>
1915-
useThingOrThingById(checkpointsOrCheckpointsId, Offsets.Checkpoints);
1924+
useThingOrThingById(checkpointsOrCheckpointsId, OFFSET_CHECKPOINTS);
19161925

19171926
export const useProvideCheckpoints: typeof useProvideCheckpointsDecl = (
19181927
checkpointsId: Id,
19191928
checkpoints: Checkpoints,
1920-
): void => useProvideThing(checkpointsId, checkpoints, Offsets.Checkpoints);
1929+
): void => useProvideThing(checkpointsId, checkpoints, OFFSET_CHECKPOINTS);
19211930

19221931
export const useCheckpointIds: typeof useCheckpointIdsDecl = (
19231932
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
@@ -2100,20 +2109,20 @@ export const useCreatePersister: typeof useCreatePersisterDecl = <
21002109
};
21012110

21022111
export const usePersisterIds: typeof usePersisterIdsDecl = () =>
2103-
useThingIds(Offsets.Persister);
2112+
useThingIds(OFFSET_PERSISTER);
21042113

21052114
export const usePersister: typeof usePersisterDecl = (
21062115
id?: Id,
2107-
): AnyPersister | undefined => useThing(id, Offsets.Persister);
2116+
): AnyPersister | undefined => useThing(id, OFFSET_PERSISTER);
21082117

21092118
export const usePersisterOrPersisterById: typeof usePersisterOrPersisterByIdDecl =
21102119
(persisterOrPersisterId?: PersisterOrPersisterId): AnyPersister | undefined =>
2111-
useThingOrThingById(persisterOrPersisterId, Offsets.Persister);
2120+
useThingOrThingById(persisterOrPersisterId, OFFSET_PERSISTER);
21122121

21132122
export const useProvidePersister: typeof useProvidePersisterDecl = (
21142123
persisterId: Id,
21152124
persister: AnyPersister,
2116-
): void => useProvideThing(persisterId, persister, Offsets.Persister);
2125+
): void => useProvideThing(persisterId, persister, OFFSET_PERSISTER);
21172126

21182127
export const usePersisterStatus: typeof usePersisterStatusDecl = (
21192128
persisterOrPersisterId?: PersisterOrPersisterId,
@@ -2173,22 +2182,22 @@ export const useCreateSynchronizer: typeof useCreateSynchronizerDecl = <
21732182
};
21742183

21752184
export const useSynchronizerIds: typeof useSynchronizerIdsDecl = () =>
2176-
useThingIds(Offsets.Synchronizer);
2185+
useThingIds(OFFSET_SYNCHRONIZER);
21772186

21782187
export const useSynchronizer: typeof useSynchronizerDecl = (
21792188
id?: Id,
2180-
): Synchronizer | undefined => useThing(id, Offsets.Synchronizer);
2189+
): Synchronizer | undefined => useThing(id, OFFSET_SYNCHRONIZER);
21812190

21822191
export const useSynchronizerOrSynchronizerById: typeof useSynchronizerOrSynchronizerByIdDecl =
21832192
(
21842193
synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId,
21852194
): Synchronizer | undefined =>
2186-
useThingOrThingById(synchronizerOrSynchronizerId, Offsets.Synchronizer);
2195+
useThingOrThingById(synchronizerOrSynchronizerId, OFFSET_SYNCHRONIZER);
21872196

21882197
export const useProvideSynchronizer: typeof useProvideSynchronizerDecl = (
21892198
persisterId: Id,
21902199
persister: Synchronizer,
2191-
): void => useProvideThing(persisterId, persister, Offsets.Synchronizer);
2200+
): void => useProvideThing(persisterId, persister, OFFSET_SYNCHRONIZER);
21922201

21932202
export const useSynchronizerStatus: typeof useSynchronizerStatusDecl = (
21942203
synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId,

0 commit comments

Comments
 (0)