Skip to content

Commit bb2ba4c

Browse files
committed
[middleware] Internal rename
1 parent 08947ca commit bb2ba4c

2 files changed

Lines changed: 56 additions & 66 deletions

File tree

‎src/middleware/index.ts‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,6 @@ export const createMiddleware = getCreateFunction(
124124
const willApplyChanges = (changes: Changes): Changes | undefined =>
125125
reduceCallbacks(willApplyChangesCallbacks, changes);
126126

127-
(store as any).setWillCallbacks(
128-
willSetContent,
129-
willSetTables,
130-
willSetTable,
131-
willSetRow,
132-
willSetCell,
133-
willSetValues,
134-
willSetValue,
135-
willDelTables,
136-
willDelTable,
137-
willDelRow,
138-
willDelCell,
139-
willDelValues,
140-
willDelValue,
141-
willApplyChanges,
142-
);
143-
144127
const getStore = (): Store => store;
145128

146129
const addWillSetContentCallback = addCallback(willSetContentCallbacks);
@@ -179,6 +162,23 @@ export const createMiddleware = getCreateFunction(
179162
destroy,
180163
} as Middleware);
181164

165+
(store as any).setMiddleware(
166+
willSetContent,
167+
willSetTables,
168+
willSetTable,
169+
willSetRow,
170+
willSetCell,
171+
willSetValues,
172+
willSetValue,
173+
willDelTables,
174+
willDelTable,
175+
willDelRow,
176+
willDelCell,
177+
willDelValues,
178+
willDelValue,
179+
willApplyChanges,
180+
);
181+
182182
return middleware;
183183
},
184184
) as typeof createMiddlewareDecl;

‎src/store/index.ts‎

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
161161
let hadTables = false;
162162
let hadValues = false;
163163
let transactions = 0;
164-
let willCallbacks: [
164+
let middleware: [
165165
willSetContent?: (content: Content) => Content | undefined,
166166
willSetTables?: (tables: Tables) => Tables | undefined,
167167
willSetTable?: (tableId: Id, table: Table) => Table | undefined,
@@ -467,28 +467,28 @@ export const createStore: typeof createStoreDecl = (): Store => {
467467
rowId: Id,
468468
cellId: Id,
469469
cell: CellOrUndefined,
470-
skipWillCallbacks?: boolean,
470+
skipMiddleware?: boolean,
471471
) =>
472472
isUndefined(cell)
473-
? delCell(tableId, rowId, cellId, true, skipWillCallbacks)
474-
: setCell(tableId, rowId, cellId, cell, skipWillCallbacks);
473+
? delCell(tableId, rowId, cellId, true, skipMiddleware)
474+
: setCell(tableId, rowId, cellId, cell, skipMiddleware);
475475

476476
const setOrDelValues = (values: Values) =>
477477
objIsEmpty(values) ? delValues() : setValues(values);
478478

479479
const setOrDelValue = (
480480
valueId: Id,
481481
value: ValueOrUndefined,
482-
skipWillCallbacks?: boolean,
482+
skipMiddleware?: boolean,
483483
) =>
484484
isUndefined(value)
485-
? delValue(valueId, skipWillCallbacks)
486-
: setValue(valueId, value, skipWillCallbacks);
485+
? delValue(valueId, skipMiddleware)
486+
: setValue(valueId, value, skipMiddleware);
487487

488488
const setValidContent = (content: Content): void =>
489489
ifNotUndefined(
490490
ifNotUndefined(
491-
willCallbacks[0],
491+
middleware[0],
492492
(willSetContent) => willSetContent(content),
493493
() => content,
494494
),
@@ -503,7 +503,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
503503
forceDel
504504
? tables
505505
: ifNotUndefined(
506-
willCallbacks[1],
506+
middleware[1],
507507
(willSetTables) => willSetTables(tables),
508508
() => tables,
509509
),
@@ -525,7 +525,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
525525
forceDel
526526
? table
527527
: ifNotUndefined(
528-
willCallbacks[2],
528+
middleware[2],
529529
(willSetTable) => willSetTable(tableId, table),
530530
() => table,
531531
),
@@ -554,7 +554,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
554554
forceDel
555555
? row
556556
: ifNotUndefined(
557-
willCallbacks[3],
557+
middleware[3],
558558
(willSetRow) => willSetRow(tableId, rowId, row),
559559
() => row,
560560
),
@@ -578,11 +578,11 @@ export const createStore: typeof createStoreDecl = (): Store => {
578578
rowMap: RowMap,
579579
cellId: Id,
580580
cell: Cell,
581-
skipWillCallbacks?: boolean,
581+
skipMiddleware?: boolean,
582582
): void =>
583583
ifNotUndefined(
584584
ifNotUndefined(
585-
skipWillCallbacks ? undefined : willCallbacks[4],
585+
skipMiddleware ? undefined : middleware[4],
586586
(willSetCell) => willSetCell(tableId, rowId, cellId, cell),
587587
() => cell,
588588
),
@@ -604,19 +604,12 @@ export const createStore: typeof createStoreDecl = (): Store => {
604604
rowId: Id,
605605
cellId: Id,
606606
validCell: Cell,
607-
skipWillCallbacks?: boolean,
607+
skipMiddleware?: boolean,
608608
): void =>
609609
ifNotUndefined(
610610
mapGet(tableMap, rowId),
611611
(rowMap): any =>
612-
setValidCell(
613-
tableId,
614-
rowId,
615-
rowMap,
616-
cellId,
617-
validCell,
618-
skipWillCallbacks,
619-
),
612+
setValidCell(tableId, rowId, rowMap, cellId, validCell, skipMiddleware),
620613
() => {
621614
const rowMap: RowMap = mapNew();
622615
mapSet(tableMap, rowId, rowMap);
@@ -630,7 +623,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
630623
rowMap,
631624
cellId,
632625
cell as Cell,
633-
skipWillCallbacks,
626+
skipMiddleware,
634627
),
635628
);
636629
},
@@ -644,7 +637,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
644637
forceDel
645638
? values
646639
: ifNotUndefined(
647-
willCallbacks[5],
640+
middleware[5],
648641
(willSetValues) => willSetValues(values),
649642
() => values,
650643
),
@@ -660,11 +653,11 @@ export const createStore: typeof createStoreDecl = (): Store => {
660653
const setValidValue = (
661654
valueId: Id,
662655
value: Value,
663-
skipWillCallbacks?: boolean,
656+
skipMiddleware?: boolean,
664657
): void =>
665658
ifNotUndefined(
666659
ifNotUndefined(
667-
skipWillCallbacks ? undefined : willCallbacks[6],
660+
skipMiddleware ? undefined : middleware[6],
668661
(willSetValue) => willSetValue(valueId, value),
669662
() => value,
670663
),
@@ -693,14 +686,14 @@ export const createStore: typeof createStoreDecl = (): Store => {
693686
mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
694687

695688
const delValidTable = (tableId: Id): TableMap => {
696-
if (willCallbacks[8]?.(tableId) ?? true) {
689+
if (middleware[8]?.(tableId) ?? true) {
697690
return setValidTable(tableId, {}, true);
698691
}
699692
return mapGet(tablesMap, tableId) as TableMap;
700693
};
701694

702695
const delValidRow = (tableId: Id, tableMap: TableMap, rowId: Id): void => {
703-
if (willCallbacks[9]?.(tableId, rowId) ?? true) {
696+
if (middleware[9]?.(tableId, rowId) ?? true) {
704697
const [, releaseId] = mapGet(
705698
tablePoolFunctions,
706699
tableId,
@@ -717,7 +710,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
717710
row: RowMap,
718711
cellId: Id,
719712
forceDel?: boolean,
720-
skipWillCallbacks?: boolean,
713+
skipMiddleware?: boolean,
721714
): void => {
722715
const defaultCell = mapGet(
723716
mapGet(tablesSchemaRowCache, tableId)?.[0],
@@ -726,10 +719,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
726719
if (!isUndefined(defaultCell) && !forceDel) {
727720
return setValidCell(tableId, rowId, row, cellId, defaultCell);
728721
}
729-
if (
730-
skipWillCallbacks ||
731-
(willCallbacks[10]?.(tableId, rowId, cellId) ?? true)
732-
) {
722+
if (skipMiddleware || (middleware[10]?.(tableId, rowId, cellId) ?? true)) {
733723
const delCell = (cellId: Id) => {
734724
cellChanged(tableId, rowId, cellId, mapGet(row, cellId));
735725
cellIdsChanged(tableId, rowId, cellId, -1);
@@ -752,12 +742,12 @@ export const createStore: typeof createStoreDecl = (): Store => {
752742
}
753743
};
754744

755-
const delValidValue = (valueId: Id, skipWillCallbacks?: boolean): void => {
745+
const delValidValue = (valueId: Id, skipMiddleware?: boolean): void => {
756746
const defaultValue = mapGet(valuesDefaulted, valueId);
757747
if (!isUndefined(defaultValue)) {
758748
return setValidValue(valueId, defaultValue);
759749
}
760-
if (skipWillCallbacks || (willCallbacks[12]?.(valueId) ?? true)) {
750+
if (skipMiddleware || (middleware[12]?.(valueId) ?? true)) {
761751
valueChanged(valueId, mapGet(valuesMap, valueId));
762752
valueIdsChanged(valueId, -1);
763753
mapSet(valuesMap, valueId);
@@ -1369,7 +1359,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
13691359
rowId: Id,
13701360
cellId: Id,
13711361
cell: Cell | MapCell,
1372-
skipWillCallbacks?: boolean,
1362+
skipMiddleware?: boolean,
13731363
): Store =>
13741364
fluentTransaction(
13751365
(tableId, rowId, cellId) =>
@@ -1387,7 +1377,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
13871377
rowId,
13881378
cellId,
13891379
validCell,
1390-
skipWillCallbacks,
1380+
skipMiddleware,
13911381
),
13921382
),
13931383
tableId,
@@ -1412,7 +1402,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
14121402
const setValue = (
14131403
valueId: Id,
14141404
value: Value,
1415-
skipWillCallbacks?: boolean,
1405+
skipMiddleware?: boolean,
14161406
): Store =>
14171407
fluentTransaction(
14181408
(valueId) =>
@@ -1421,7 +1411,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
14211411
valueId,
14221412
isFunction(value) ? value(getValue(valueId)) : value,
14231413
),
1424-
(validValue) => setValidValue(valueId, validValue, skipWillCallbacks),
1414+
(validValue) => setValidValue(valueId, validValue, skipMiddleware),
14251415
),
14261416
valueId,
14271417
);
@@ -1430,7 +1420,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
14301420
fluentTransaction(() =>
14311421
ifNotUndefined(
14321422
ifNotUndefined(
1433-
willCallbacks[13],
1423+
middleware[13],
14341424
(willApplyChanges) => willApplyChanges(changes),
14351425
() => changes,
14361426
),
@@ -1515,7 +1505,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
15151505

15161506
const delTables = (): Store =>
15171507
fluentTransaction(() =>
1518-
(willCallbacks[7]?.() ?? true) ? setValidTables({}, true) : 0,
1508+
(middleware[7]?.() ?? true) ? setValidTables({}, true) : 0,
15191509
);
15201510

15211511
const delTable = (tableId: Id): Store =>
@@ -1539,7 +1529,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
15391529
rowId: Id,
15401530
cellId: Id,
15411531
forceDel?: boolean,
1542-
skipWillCallbacks?: boolean,
1532+
skipMiddleware?: boolean,
15431533
): Store =>
15441534
fluentTransaction(
15451535
(tableId, rowId, cellId) =>
@@ -1553,7 +1543,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
15531543
rowMap,
15541544
cellId,
15551545
forceDel,
1556-
skipWillCallbacks,
1546+
skipMiddleware,
15571547
)
15581548
: 0,
15591549
),
@@ -1565,14 +1555,14 @@ export const createStore: typeof createStoreDecl = (): Store => {
15651555

15661556
const delValues = (): Store =>
15671557
fluentTransaction(() =>
1568-
(willCallbacks[11]?.() ?? true) ? setValidValues({}, true) : 0,
1558+
(middleware[11]?.() ?? true) ? setValidValues({}, true) : 0,
15691559
);
15701560

1571-
const delValue = (valueId: Id, skipWillCallbacks?: boolean): Store =>
1561+
const delValue = (valueId: Id, skipMiddleware?: boolean): Store =>
15721562
fluentTransaction(
15731563
(valueId) =>
15741564
collHas(valuesMap, valueId)
1575-
? delValidValue(valueId, skipWillCallbacks)
1565+
? delValidValue(valueId, skipMiddleware)
15761566
: 0,
15771567
valueId,
15781568
);
@@ -1842,7 +1832,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
18421832
pairCollSize2(finishTransactionListeners),
18431833
});
18441834

1845-
const setWillCallbacks = (
1835+
const setMiddleware = (
18461836
willSetContent: (content: Content) => Content | undefined,
18471837
willSetTables: (tables: Tables) => Tables | undefined,
18481838
willSetTable: (tableId: Id, table: Table) => Table | undefined,
@@ -1863,7 +1853,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
18631853
willDelValue: (valueId: Id) => boolean,
18641854
willApplyChanges: (changes: Changes) => Changes | undefined,
18651855
) =>
1866-
(willCallbacks = [
1856+
(middleware = [
18671857
willSetContent,
18681858
willSetTables,
18691859
willSetTable,
@@ -1997,7 +1987,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
19971987
addListener,
19981988
callListeners,
19991989
setInternalListeners,
2000-
setWillCallbacks,
1990+
setMiddleware,
20011991
setOrDelCell,
20021992
setOrDelValue,
20031993
};

0 commit comments

Comments
 (0)