Skip to content

Commit 31fb1f3

Browse files
committed
[hygiene] String sharing
1 parent 0b3b39b commit 31fb1f3

File tree

7 files changed

+73
-39
lines changed

7 files changed

+73
-39
lines changed

src/common/strings.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export const MAX = 'max';
2424
export const LISTENER = 'Listener';
2525
export const RESULT = 'Result';
2626
export const GET = 'get';
27+
export const SET = 'set';
2728
export const ADD = 'add';
29+
export const DEL = 'del';
2830
export const HAS = 'Has';
2931
export const _HAS = 'has';
3032

@@ -43,8 +45,20 @@ export const VALUES = VALUE + 's';
4345
export const VALUE_IDS = VALUE + IDS;
4446
export const TRANSACTION = 'Transaction';
4547

48+
export const PARTIAL = 'Partial';
49+
export const FINISH = 'Finish';
4650
export const STATUS = 'Status';
4751

52+
export const METRIC = 'Metric';
53+
export const INDEX = 'Index';
54+
export const SLICE = 'Slice';
55+
export const RELATIONSHIP = 'Relationship';
56+
export const REMOTE_ROW_ID = 'Remote' + ROW + 'Id';
57+
export const LOCAL = 'Local';
58+
export const LINKED = 'Linked';
59+
export const QUERY = 'Query';
60+
export const CHECKPOINT = 'Checkpoint';
61+
4862
export const CURRENT_TARGET = 'currentTarget';
4963
export const _VALUE = 'value';
5064

src/mergeable-store/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import {
2+
ADD,
3+
DEL,
4+
EMPTY_STRING,
5+
LISTENER,
6+
SET,
7+
TRANSACTION,
8+
strEndsWith,
9+
strStartsWith,
10+
} from '../common/strings.ts';
111
import type {
212
CellHashes,
313
ContentHashes,
@@ -22,7 +32,6 @@ import type {
2232
Store,
2333
ValueOrUndefined,
2434
} from '../@types/store/index.d.ts';
25-
import {EMPTY_STRING, strEndsWith, strStartsWith} from '../common/strings.ts';
2635
import {
2736
IdObj,
2837
objEnsure,
@@ -616,16 +625,16 @@ export const createMergeableStore = ((uniqueId?: Id): MergeableStore => {
616625
(method, name) =>
617626
(mergeableStore[name] =
618627
// fluent methods
619-
strStartsWith(name, 'set') ||
620-
strStartsWith(name, 'del') ||
628+
strStartsWith(name, SET) ||
629+
strStartsWith(name, DEL) ||
621630
strStartsWith(name, 'apply') ||
622-
strEndsWith(name, 'Transaction') ||
623-
name == 'callListener'
631+
strEndsWith(name, TRANSACTION) ||
632+
name == 'call' + LISTENER
624633
? (...args: any[]) => {
625634
method(...args);
626635
return mergeableStore;
627636
}
628-
: strStartsWith(name, 'add') && strEndsWith(name, 'Listener')
637+
: strStartsWith(name, ADD) && strEndsWith(name, LISTENER)
629638
? (...args: any[]) => {
630639
const listenerArg = LISTENER_ARGS[slice(name, 3, -8)] ?? 0;
631640
const listener = args[listenerArg];

src/queries/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
269269
selectedCellId,
270270
isFunction(aggregate)
271271
? [aggregate, aggregateAdd, aggregateRemove, aggregateReplace]
272-
: (mapGet(numericAggregators, aggregate as Id) as Aggregators) ?? [
272+
: ((mapGet(numericAggregators, aggregate as Id) as Aggregators) ?? [
273273
(_cells, length) => length,
274-
],
274+
]),
275275
],
276276
];
277277
arrayPush(groupEntries, groupEntry);

src/tools/api/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
HAS,
99
IDS,
1010
LISTENER,
11+
PARTIAL,
1112
ROW,
1213
ROW_IDS,
1314
SORTED_ROW_IDS,
@@ -35,7 +36,6 @@ import {
3536
LISTENER_,
3637
METHOD_PREFIX_VERBS,
3738
OR_UNDEFINED,
38-
PARTIAL,
3939
REGISTERS_A_LISTENER,
4040
REPRESENTS,
4141
ROW_ID_PARAM,

src/tools/api/react.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
LISTENER_,
1212
OPTIONAL_COLON,
1313
OR_UNDEFINED,
14-
PARTIAL,
1514
PROPS,
1615
PROVIDER,
1716
RETURNS_VOID,
@@ -42,6 +41,7 @@ import {
4241
IDS,
4342
LISTENER,
4443
NUMBER,
44+
PARTIAL,
4545
ROW,
4646
ROW_IDS,
4747
SORTED_ROW_IDS,

src/tools/common/strings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const LISTENER_ = lower(LISTENER);
4040
export const OPTIONAL_COLON = '?: ';
4141
export const OR_UNDEFINED = ' | undefined';
4242
export const NON_NULLABLE = 'NonNullable';
43-
export const PARTIAL = 'Partial';
4443
export const PROPS = 'Props';
4544
export const PROVIDER = 'Provider';
4645
export const REGISTERS_A_LISTENER = `Registers a ${LISTENER_} that will be called`;

src/ui-react/hooks.ts

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ import {
22
ADD,
33
CELL,
44
CELL_IDS,
5+
CHECKPOINT,
6+
DEL,
57
EMPTY_STRING,
8+
FINISH,
69
GET,
710
HAS,
11+
IDS,
12+
INDEX,
13+
LINKED,
814
LISTENER,
15+
LOCAL,
16+
METRIC,
17+
PARTIAL,
18+
QUERY,
19+
RELATIONSHIP,
20+
REMOTE_ROW_ID,
921
RESULT,
1022
ROW,
1123
ROW_COUNT,
1224
ROW_IDS,
25+
SET,
26+
SLICE,
1327
SORTED_ROW_IDS,
1428
STATUS,
1529
TABLE,
@@ -413,7 +427,7 @@ const useSetCallback = <Parameter, Thing>(
413427
ifNotUndefined(store, (store: any) =>
414428
ifNotUndefined(get(parameter as any, store), (thing: Thing) =>
415429
then(
416-
store['set' + settable](
430+
store[SET + settable](
417431
...argsOrGetArgs(args, store, parameter),
418432
thing,
419433
),
@@ -449,9 +463,7 @@ const useDel = <Parameter>(
449463
const store: any = useStoreOrStoreById(storeOrStoreId);
450464
return useCallback(
451465
(parameter?: Parameter) =>
452-
then(
453-
store?.['del' + deletable](...argsOrGetArgs(args, store, parameter)),
454-
),
466+
then(store?.[DEL + deletable](...argsOrGetArgs(args, store, parameter))),
455467
// eslint-disable-next-line react-hooks/exhaustive-deps
456468
[store, deletable, ...thenDeps, ...nonFunctionDeps(args)],
457469
);
@@ -789,7 +801,7 @@ export const useSetPartialRowCallback: typeof useSetPartialRowCallbackDecl = <
789801
): ParameterizedCallback<Parameter> =>
790802
useSetCallback(
791803
storeOrStoreId,
792-
'PartialRow',
804+
PARTIAL + ROW,
793805
getPartialRow,
794806
getPartialRowDeps,
795807
then,
@@ -848,7 +860,7 @@ export const useSetPartialValuesCallback: typeof useSetPartialValuesCallbackDecl
848860
): ParameterizedCallback<Parameter> =>
849861
useSetCallback(
850862
storeOrStoreId,
851-
'PartialValues',
863+
PARTIAL + VALUES,
852864
getPartialValues,
853865
getPartialValuesDeps,
854866
then,
@@ -1276,7 +1288,7 @@ export const useWillFinishTransactionListener: typeof useWillFinishTransactionLi
12761288
storeOrStoreId?: StoreOrStoreId,
12771289
): void =>
12781290
useListener(
1279-
'WillFinish' + TRANSACTION,
1291+
'Will' + FINISH + TRANSACTION,
12801292
useStoreOrStoreById(storeOrStoreId),
12811293
listener,
12821294
listenerDeps,
@@ -1289,7 +1301,7 @@ export const useDidFinishTransactionListener: typeof useDidFinishTransactionList
12891301
storeOrStoreId?: StoreOrStoreId,
12901302
): void =>
12911303
useListener(
1292-
'DidFinish' + TRANSACTION,
1304+
'Did' + FINISH + TRANSACTION,
12931305
useStoreOrStoreById(storeOrStoreId),
12941306
listener,
12951307
listenerDeps,
@@ -1305,7 +1317,7 @@ export const useMetricIds: typeof useMetricIdsDecl = (
13051317
metricsOrMetricsId?: MetricsOrMetricsId,
13061318
): Ids =>
13071319
useListenable(
1308-
'MetricIds',
1320+
METRIC + IDS,
13091321
useMetricsOrMetricsById(metricsOrMetricsId),
13101322
ReturnType.Array,
13111323
);
@@ -1315,7 +1327,7 @@ export const useMetric: typeof useMetricDecl = (
13151327
metricsOrMetricsId?: MetricsOrMetricsId,
13161328
): number | undefined =>
13171329
useListenable(
1318-
'Metric',
1330+
METRIC,
13191331
useMetricsOrMetricsById(metricsOrMetricsId),
13201332
ReturnType.CellOrValue,
13211333
[metricId],
@@ -1328,7 +1340,7 @@ export const useMetricListener: typeof useMetricListenerDecl = (
13281340
metricsOrMetricsId?: MetricsOrMetricsId,
13291341
): void =>
13301342
useListener(
1331-
'Metric',
1343+
METRIC,
13321344
useMetricsOrMetricsById(metricsOrMetricsId),
13331345
listener,
13341346
listenerDeps,
@@ -1346,7 +1358,7 @@ export const useSliceIds: typeof useSliceIdsDecl = (
13461358
indexesOrIndexesId?: IndexesOrIndexesId,
13471359
): Ids =>
13481360
useListenable(
1349-
'SliceIds',
1361+
SLICE + IDS,
13501362
useIndexesOrIndexesById(indexesOrIndexesId),
13511363
ReturnType.Array,
13521364
[indexId],
@@ -1356,7 +1368,7 @@ export const useIndexIds: typeof useIndexIdsDecl = (
13561368
indexesOrIndexesId?: IndexesOrIndexesId,
13571369
): Ids =>
13581370
useListenable(
1359-
'IndexIds',
1371+
INDEX + IDS,
13601372
useIndexesOrIndexesById(indexesOrIndexesId),
13611373
ReturnType.Array,
13621374
);
@@ -1367,7 +1379,7 @@ export const useSliceRowIds: typeof useSliceRowIdsDecl = (
13671379
indexesOrIndexesId?: IndexesOrIndexesId,
13681380
): Ids =>
13691381
useListenable(
1370-
'Slice' + ROW_IDS,
1382+
SLICE + ROW_IDS,
13711383
useIndexesOrIndexesById(indexesOrIndexesId),
13721384
ReturnType.Array,
13731385
[indexId, sliceId],
@@ -1380,7 +1392,7 @@ export const useSliceIdsListener: typeof useSliceIdsListenerDecl = (
13801392
indexesOrIndexesId?: IndexesOrIndexesId,
13811393
): void =>
13821394
useListener(
1383-
'SliceIds',
1395+
SLICE + IDS,
13841396
useIndexesOrIndexesById(indexesOrIndexesId),
13851397
listener,
13861398
listenerDeps,
@@ -1395,7 +1407,7 @@ export const useSliceRowIdsListener: typeof useSliceRowIdsListenerDecl = (
13951407
indexesOrIndexesId?: IndexesOrIndexesId,
13961408
): void =>
13971409
useListener(
1398-
'Slice' + ROW_IDS,
1410+
SLICE + ROW_IDS,
13991411
useIndexesOrIndexesById(indexesOrIndexesId),
14001412
listener,
14011413
listenerDeps,
@@ -1412,7 +1424,7 @@ export const useRelationshipIds: typeof useRelationshipIdsDecl = (
14121424
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14131425
): Ids =>
14141426
useListenable(
1415-
'RelationshipIds',
1427+
RELATIONSHIP + IDS,
14161428
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14171429
ReturnType.Array,
14181430
);
@@ -1423,7 +1435,7 @@ export const useRemoteRowId: typeof useRemoteRowIdDecl = (
14231435
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14241436
): Id | undefined =>
14251437
useListenable(
1426-
'RemoteRowId',
1438+
REMOTE_ROW_ID,
14271439
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14281440
ReturnType.CellOrValue,
14291441
[relationshipId, localRowId],
@@ -1435,7 +1447,7 @@ export const useLocalRowIds: typeof useLocalRowIdsDecl = (
14351447
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14361448
): Ids =>
14371449
useListenable(
1438-
'Local' + ROW_IDS,
1450+
LOCAL + ROW_IDS,
14391451
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14401452
ReturnType.Array,
14411453
[relationshipId, remoteRowId],
@@ -1447,7 +1459,7 @@ export const useLinkedRowIds: typeof useLinkedRowIdsDecl = (
14471459
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14481460
): Ids =>
14491461
useListenable(
1450-
'Linked' + ROW_IDS,
1462+
LINKED + ROW_IDS,
14511463
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14521464
ReturnType.Array,
14531465
[relationshipId, firstRowId],
@@ -1461,7 +1473,7 @@ export const useRemoteRowIdListener: typeof useRemoteRowIdListenerDecl = (
14611473
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14621474
): void =>
14631475
useListener(
1464-
'RemoteRowId',
1476+
REMOTE_ROW_ID,
14651477
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14661478
listener,
14671479
listenerDeps,
@@ -1476,7 +1488,7 @@ export const useLocalRowIdsListener: typeof useLocalRowIdsListenerDecl = (
14761488
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14771489
): void =>
14781490
useListener(
1479-
'Local' + ROW_IDS,
1491+
LOCAL + ROW_IDS,
14801492
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14811493
listener,
14821494
listenerDeps,
@@ -1491,7 +1503,7 @@ export const useLinkedRowIdsListener: typeof useLinkedRowIdsListenerDecl = (
14911503
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
14921504
): void =>
14931505
useListener(
1494-
'Linked' + ROW_IDS,
1506+
LINKED + ROW_IDS,
14951507
useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
14961508
listener,
14971509
listenerDeps,
@@ -1508,7 +1520,7 @@ export const useQueryIds: typeof useQueryIdsDecl = (
15081520
queriesOrQueriesId?: QueriesOrQueriesId,
15091521
): Ids =>
15101522
useListenable(
1511-
'QueryIds',
1523+
QUERY + IDS,
15121524
useQueriesOrQueriesById(queriesOrQueriesId),
15131525
ReturnType.Array,
15141526
);
@@ -1741,7 +1753,7 @@ export const useCheckpointIds: typeof useCheckpointIdsDecl = (
17411753
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
17421754
): CheckpointIds =>
17431755
useListenable(
1744-
'CheckpointIds',
1756+
CHECKPOINT + IDS,
17451757
useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId),
17461758
ReturnType.Checkpoints,
17471759
);
@@ -1751,7 +1763,7 @@ export const useCheckpoint: typeof useCheckpointDecl = (
17511763
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
17521764
): string | undefined =>
17531765
useListenable(
1754-
'Checkpoint',
1766+
CHECKPOINT,
17551767
useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId),
17561768
ReturnType.CellOrValue,
17571769
[checkpointId],
@@ -1852,7 +1864,7 @@ export const useCheckpointIdsListener: typeof useCheckpointIdsListenerDecl = (
18521864
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
18531865
): void =>
18541866
useListener(
1855-
'CheckpointIds',
1867+
CHECKPOINT + IDS,
18561868
useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId),
18571869
listener,
18581870
listenerDeps,
@@ -1865,7 +1877,7 @@ export const useCheckpointListener: typeof useCheckpointListenerDecl = (
18651877
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
18661878
): void =>
18671879
useListener(
1868-
'Checkpoint',
1880+
CHECKPOINT,
18691881
useCheckpointsOrCheckpointsById(checkpointsOrCheckpointsId),
18701882
listener,
18711883
listenerDeps,

0 commit comments

Comments
 (0)