Skip to content

Commit 304ebed

Browse files
committed
[svelte] Spell out shortened variable names
1 parent af912bd commit 304ebed

1 file changed

Lines changed: 66 additions & 50 deletions

File tree

src/ui-svelte/functions.svelte.ts

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -245,32 +245,35 @@ export const resolveSynchronizer = (
245245
OFFSET_SYNCHRONIZER,
246246
);
247247

248-
const createListenable = <T>(
248+
const createListenable = <Thing>(
249249
getThing: () => any,
250250
listenable: string,
251-
defaultValue: T,
251+
defaultValue: Thing,
252252
getArgs: () => readonly any[] = () => EMPTY_ARR,
253253
isHas?: 0 | 1,
254-
): {readonly current: T} => {
255-
const getMethod = (isHas ? _HAS : GET) + listenable;
256-
const addMethod = ADD + (isHas ? HAS : '') + listenable + LISTENER;
257-
let value = $state<T>(
258-
(getThing()?.[getMethod]?.(...getArgs()) ?? defaultValue) as T,
254+
): {readonly current: Thing} => {
255+
const getListenableMethod = (isHas ? _HAS : GET) + listenable;
256+
const addListenableMethod = ADD + (isHas ? HAS : '') + listenable + LISTENER;
257+
let value = $state<Thing>(
258+
(getThing()?.[getListenableMethod]?.(...getArgs()) ??
259+
defaultValue) as Thing,
259260
);
260261
if (hasWindow()) {
261262
$effect(() => {
262263
const thing = getThing();
263264
const args = getArgs();
264-
value = (thing?.[getMethod]?.(...args) ?? defaultValue) as T;
265-
const listenerId = thing?.[addMethod]?.(...args, () => {
266-
value = (thing[getMethod](...getArgs()) ?? defaultValue) as T;
265+
const listenerId = thing?.[addListenableMethod]?.(...args, () => {
266+
value = (thing[getListenableMethod](...getArgs()) ??
267+
defaultValue) as Thing;
267268
});
269+
value = (thing?.[getListenableMethod]?.(...args) ??
270+
defaultValue) as Thing;
268271
return () => thing?.delListener?.(listenerId);
269272
});
270273
}
271274
return {
272-
get current(): T {
273-
return value as T;
275+
get current(): Thing {
276+
return value as Thing;
274277
},
275278
};
276279
};
@@ -454,31 +457,41 @@ export const createCell = (
454457
cellId: MaybeGetter<Id>,
455458
storeOrStoreId?: MaybeGetter<Store | Id | undefined>,
456459
): {get current(): CellOrUndefined; set current(v: Cell)} => {
457-
const getS = resolveStore(storeOrStoreId);
460+
const getStore = resolveStore(storeOrStoreId);
458461
let value = $state<CellOrUndefined>(
459-
getS()?.getCell(maybeGet(tableId), maybeGet(rowId), maybeGet(cellId)),
462+
getStore()?.getCell(maybeGet(tableId), maybeGet(rowId), maybeGet(cellId)),
460463
);
461464
if (hasWindow()) {
462465
$effect(() => {
463-
const s: any = getS();
464-
const t = maybeGet(tableId),
465-
r = maybeGet(rowId),
466-
c = maybeGet(cellId);
467-
value = s?.getCell(t, r, c);
468-
const listenerId = s?.addCellListener(t, r, c, (st: any) => {
469-
value = st.getCell(
470-
maybeGet(tableId),
471-
maybeGet(rowId),
472-
maybeGet(cellId),
473-
);
474-
});
475-
return () => s?.delListener?.(listenerId);
466+
const store: any = getStore();
467+
const tableIdValue = maybeGet(tableId);
468+
const rowIdValue = maybeGet(rowId);
469+
const cellIdValue = maybeGet(cellId);
470+
const listenerId = store?.addCellListener(
471+
tableIdValue,
472+
rowIdValue,
473+
cellIdValue,
474+
(changedStore: any) => {
475+
value = changedStore.getCell(
476+
maybeGet(tableId),
477+
maybeGet(rowId),
478+
maybeGet(cellId),
479+
);
480+
},
481+
);
482+
value = store?.getCell(tableIdValue, rowIdValue, cellIdValue);
483+
return () => store?.delListener?.(listenerId);
476484
});
477485
}
478486
return new WritableHandle<Cell>(
479487
() => value,
480-
(v) =>
481-
getS()?.setCell(maybeGet(tableId), maybeGet(rowId), maybeGet(cellId), v),
488+
(nextCell) =>
489+
getStore()?.setCell(
490+
maybeGet(tableId),
491+
maybeGet(rowId),
492+
maybeGet(cellId),
493+
nextCell,
494+
),
482495
);
483496
};
484497

@@ -519,22 +532,25 @@ export const createValue = (
519532
valueId: MaybeGetter<Id>,
520533
storeOrStoreId?: MaybeGetter<Store | Id | undefined>,
521534
): {get current(): ValueOrUndefined; set current(v: Value)} => {
522-
const getS = resolveStore(storeOrStoreId);
523-
let value = $state<ValueOrUndefined>(getS()?.getValue(maybeGet(valueId)));
535+
const getStore = resolveStore(storeOrStoreId);
536+
let value = $state<ValueOrUndefined>(getStore()?.getValue(maybeGet(valueId)));
524537
if (hasWindow()) {
525538
$effect(() => {
526-
const s: any = getS();
527-
const vid = maybeGet(valueId);
528-
value = s?.getValue(vid);
529-
const listenerId = s?.addValueListener(vid, (st: any) => {
530-
value = st.getValue(maybeGet(valueId));
531-
});
532-
return () => s?.delListener?.(listenerId);
539+
const store: any = getStore();
540+
const valueIdValue = maybeGet(valueId);
541+
const listenerId = store?.addValueListener(
542+
valueIdValue,
543+
(changedStore: any) => {
544+
value = changedStore.getValue(maybeGet(valueId));
545+
},
546+
);
547+
value = store?.getValue(valueIdValue);
548+
return () => store?.delListener?.(listenerId);
533549
});
534550
}
535551
return new WritableHandle<Value>(
536552
() => value,
537-
(v) => getS()?.setValue(maybeGet(valueId), v),
553+
(nextValue) => getStore()?.setValue(maybeGet(valueId), nextValue),
538554
);
539555
};
540556

@@ -640,13 +656,13 @@ export const getIndexStoreTableId = (
640656
indexesOrId: MaybeGetter<Indexes | Id | undefined>,
641657
indexId: MaybeGetter<Id>,
642658
) => {
643-
const getI = resolveIndexes(indexesOrId);
659+
const getIndexes = resolveIndexes(indexesOrId);
644660
return {
645661
get store() {
646-
return getI()?.getStore();
662+
return getIndexes()?.getStore();
647663
},
648664
get tableId() {
649-
return getI()?.getTableId(maybeGet(indexId));
665+
return getIndexes()?.getTableId(maybeGet(indexId));
650666
},
651667
};
652668
};
@@ -843,16 +859,16 @@ export const getRelationshipsStoreTableIds = (
843859
relationshipsOrId: MaybeGetter<Relationships | Id | undefined>,
844860
relationshipId: MaybeGetter<Id>,
845861
) => {
846-
const getR = resolveRelationships(relationshipsOrId);
862+
const getRelationships = resolveRelationships(relationshipsOrId);
847863
return {
848864
get store() {
849-
return getR()?.getStore();
865+
return getRelationships()?.getStore();
850866
},
851867
get localTableId() {
852-
return getR()?.getLocalTableId(maybeGet(relationshipId));
868+
return getRelationships()?.getLocalTableId(maybeGet(relationshipId));
853869
},
854870
get remoteTableId() {
855-
return getR()?.getRemoteTableId(maybeGet(relationshipId));
871+
return getRelationships()?.getRemoteTableId(maybeGet(relationshipId));
856872
},
857873
};
858874
};
@@ -898,15 +914,15 @@ export const createCheckpoint = (
898914
export const createGoBackwardCallback = (
899915
checkpointsOrCheckpointsId?: MaybeGetter<Checkpoints | Id | undefined>,
900916
): (() => void) => {
901-
const getC = resolveCheckpoints(checkpointsOrCheckpointsId);
902-
return () => getC()?.goBackward();
917+
const getCheckpoints = resolveCheckpoints(checkpointsOrCheckpointsId);
918+
return () => getCheckpoints()?.goBackward();
903919
};
904920

905921
export const createGoForwardCallback = (
906922
checkpointsOrCheckpointsId?: MaybeGetter<Checkpoints | Id | undefined>,
907923
): (() => void) => {
908-
const getC = resolveCheckpoints(checkpointsOrCheckpointsId);
909-
return () => getC()?.goForward();
924+
const getCheckpoints = resolveCheckpoints(checkpointsOrCheckpointsId);
925+
return () => getCheckpoints()?.goForward();
910926
};
911927

912928
export const getPersister = (id?: Id): AnyPersister | undefined =>

0 commit comments

Comments
 (0)