Skip to content

Commit 561d73b

Browse files
committed
[hygiene] Nested ternaries
1 parent 44cc453 commit 561d73b

File tree

16 files changed

+127
-168
lines changed

16 files changed

+127
-168
lines changed

src/checkpoints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ export const createCheckpoints = getCreateFunction(
267267
const action = arrayHas(backwardIds, checkpointId)
268268
? goBackwardImpl
269269
: arrayHas(forwardIds, checkpointId)
270-
? goForwardImpl
271-
: null;
270+
? goForwardImpl
271+
: null;
272272
while (!isUndefined(action) && checkpointId != currentId) {
273273
action();
274274
}

src/common/aggregators.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,17 @@ export const getAggregateValue = <Value, AggregateValue>(
9595
oldLength++,
9696
)
9797
: isUndefined(newValue)
98-
? aggregateRemove?.(
99-
aggregateValue as AggregateValue,
100-
oldValue,
101-
oldLength--,
102-
)
103-
: aggregateReplace?.(
104-
aggregateValue as AggregateValue,
105-
newValue,
106-
oldValue,
107-
oldLength,
108-
);
98+
? aggregateRemove?.(
99+
aggregateValue as AggregateValue,
100+
oldValue,
101+
oldLength--,
102+
)
103+
: aggregateReplace?.(
104+
aggregateValue as AggregateValue,
105+
newValue,
106+
oldValue,
107+
oldLength,
108+
);
109109
force ||= isUndefined(aggregateValue);
110110
}
111111
});

src/common/listeners.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ const getWildcardedLeaves = (
116116
p == size(path)
117117
? arrayPush(leaves, node)
118118
: path[p] === null
119-
? collForEach(node as Node<IdOrNull, IdSet>, (node) => deep(node, p + 1))
120-
: arrayForEach([path[p], null], (id) =>
121-
deep(mapGet(node as Node<IdOrNull, IdSet>, id) as IdSetNode, p + 1),
122-
);
119+
? collForEach(node as Node<IdOrNull, IdSet>, (node) =>
120+
deep(node, p + 1),
121+
)
122+
: arrayForEach([path[p], null], (id) =>
123+
deep(mapGet(node as Node<IdOrNull, IdSet>, id) as IdSetNode, p + 1),
124+
);
123125
deep(deepIdSet, 0);
124126
return leaves;
125127
};
@@ -206,10 +208,10 @@ export const getListenerFunctions = (
206208
index == size(path)
207209
? (listener as any)(thing, ...ids, ...extraArgsGetter(ids))
208210
: isUndefined(path[index])
209-
? arrayForEach(pathGetters[index]?.(...ids) ?? [], (id) =>
210-
callWithIds(...ids, id),
211-
)
212-
: callWithIds(...ids, path[index] as Id);
211+
? arrayForEach(pathGetters[index]?.(...ids) ?? [], (id) =>
212+
callWithIds(...ids, id),
213+
)
214+
: callWithIds(...ids, path[index] as Id);
213215
};
214216
callWithIds();
215217
},

src/indexes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export const createIndexes = getCreateFunction((store: Store): Indexes => {
5959
isUndefined(value)
6060
? EMPTY_STRING
6161
: isArray(value)
62-
? arrayMap(value, id)
63-
: id(value),
62+
? arrayMap(value, id)
63+
: id(value),
6464
addListener,
6565
callListeners,
6666
);

src/persisters/persister-automerge.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,35 @@ const setTransactionChangesToDoc = (
5151
transactionChangesFailed
5252
? 0
5353
: isUndefined(table)
54-
? objDel(docTables, tableId)
55-
: ifNotUndefined(
56-
docTables[tableId],
57-
(docTable) =>
58-
objMap(table, (row, rowId) =>
59-
transactionChangesFailed
60-
? 0
61-
: isUndefined(row)
62-
? objDel(docTable, rowId)
63-
: ifNotUndefined(
64-
objGet(docTable, rowId),
65-
(docRow: any) =>
66-
objMap(row, (cell, cellId) =>
67-
isUndefined(cell)
68-
? objDel(docRow, cellId)
69-
: (docRow[cellId] = cell),
54+
? objDel(docTables, tableId)
55+
: ifNotUndefined(
56+
docTables[tableId],
57+
(docTable) =>
58+
objMap(table, (row, rowId) =>
59+
transactionChangesFailed
60+
? 0
61+
: isUndefined(row)
62+
? objDel(docTable, rowId)
63+
: ifNotUndefined(
64+
objGet(docTable, rowId),
65+
(docRow: any) =>
66+
objMap(row, (cell, cellId) =>
67+
isUndefined(cell)
68+
? objDel(docRow, cellId)
69+
: (docRow[cellId] = cell),
70+
),
71+
transactionChangesDidFail as any,
7072
),
71-
transactionChangesDidFail as any,
72-
),
73-
),
74-
transactionChangesDidFail,
75-
),
73+
),
74+
transactionChangesDidFail,
75+
),
7676
);
7777
objMap(valueChanges, (value, valueId) =>
7878
transactionChangesFailed
7979
? 0
8080
: isUndefined(value)
81-
? objDel(docValues, valueId)
82-
: (docValues[valueId] = value),
81+
? objDel(docValues, valueId)
82+
: (docValues[valueId] = value),
8383
);
8484
});
8585
if (transactionChangesFailed) {

src/persisters/persister-yjs.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,35 @@ const setTransactionChangesToYDoc = (
100100
transactionChangesFailed
101101
? 0
102102
: isUndefined(table)
103-
? yTables.delete(tableId)
104-
: ifNotUndefined(
105-
yTables.get(tableId),
106-
(yTable) =>
107-
objMap(table, (row, rowId) =>
108-
transactionChangesFailed
109-
? 0
110-
: isUndefined(row)
111-
? yTable.delete(rowId)
112-
: ifNotUndefined(
113-
yTable.get(rowId),
114-
(yRow) =>
115-
objMap(row, (cell, cellId) =>
116-
isUndefined(cell)
117-
? yRow.delete(cellId)
118-
: yRow.set(cellId, cell),
103+
? yTables.delete(tableId)
104+
: ifNotUndefined(
105+
yTables.get(tableId),
106+
(yTable) =>
107+
objMap(table, (row, rowId) =>
108+
transactionChangesFailed
109+
? 0
110+
: isUndefined(row)
111+
? yTable.delete(rowId)
112+
: ifNotUndefined(
113+
yTable.get(rowId),
114+
(yRow) =>
115+
objMap(row, (cell, cellId) =>
116+
isUndefined(cell)
117+
? yRow.delete(cellId)
118+
: yRow.set(cellId, cell),
119+
),
120+
transactionChangesDidFail,
119121
),
120-
transactionChangesDidFail,
121-
),
122-
),
123-
transactionChangesDidFail,
124-
),
122+
),
123+
transactionChangesDidFail,
124+
),
125125
);
126126
objMap(valueChanges, (value, valueId) =>
127127
transactionChangesFailed
128128
? 0
129129
: isUndefined(value)
130-
? yValues.delete(valueId)
131-
: yValues.set(valueId, value),
130+
? yValues.delete(valueId)
131+
: yValues.set(valueId, value),
132132
);
133133
});
134134
if (transactionChangesFailed) {

src/queries.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
252252
isFunction(arg1)
253253
? arg1
254254
: isUndefined(arg3)
255-
? (getTableCell) => getTableCell(arg1) === arg2
256-
: (getTableCell) => getTableCell(arg1, arg2 as Id) === arg3,
255+
? (getTableCell) => getTableCell(arg1) === arg2
256+
: (getTableCell) => getTableCell(arg1, arg2 as Id) === arg3,
257257
);
258258

259259
const group = (
@@ -477,12 +477,12 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
477477
...((isUndefined(arg2)
478478
? [tableId, rootRowId, arg1]
479479
: arg1 === tableId
480-
? [tableId, rootRowId, arg2]
481-
: [
482-
mapGet(joins, arg1)?.[0] as Id,
483-
mapGet(mapGet(joins, arg1)?.[4], rootRowId)?.[0],
484-
arg2,
485-
]) as [Id, Id, Id]),
480+
? [tableId, rootRowId, arg2]
481+
: [
482+
mapGet(joins, arg1)?.[0] as Id,
483+
mapGet(mapGet(joins, arg1)?.[4], rootRowId)?.[0],
484+
arg2,
485+
]) as [Id, Id, Id]),
486486
);
487487
selectJoinWhereStore.transaction(() =>
488488
arrayEvery(wheres, (where) => where(getTableCell))

src/store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ export const createStore: typeof createStoreDecl = (): Store => {
297297
() => cellInvalid(tableId, rowId, cellId, cell),
298298
)
299299
: isUndefined(getCellOrValueType(cell))
300-
? cellInvalid(tableId, rowId, cellId, cell)
301-
: cell;
300+
? cellInvalid(tableId, rowId, cellId, cell)
301+
: cell;
302302

303303
const validateValues = (values: Values, skipDefaults?: 1): boolean =>
304304
validate(
@@ -326,8 +326,8 @@ export const createStore: typeof createStoreDecl = (): Store => {
326326
() => valueInvalid(valueId, value),
327327
)
328328
: isUndefined(getCellOrValueType(value))
329-
? valueInvalid(valueId, value)
330-
: value;
329+
? valueInvalid(valueId, value)
330+
: value;
331331

332332
const addDefaultsToRow = (row: Row, tableId: Id, rowId?: Id): Row => {
333333
ifNotUndefined(

src/tools/common/code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ export const getCodeFunctions = (): [
177177
? -1
178178
: 1
179179
: import1 > import2
180-
? 1
181-
: -1,
180+
? 1
181+
: -1,
182182
),
183183
EMPTY_STRING,
184184
],

src/types/docs/metrics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@
351351
* remove == metric
352352
* ? undefined
353353
* : add > 2
354-
* ? Math.min(metric, add)
355-
* : metric,
354+
* ? Math.min(metric, add)
355+
* : metric,
356356
* );
357357
*
358358
* console.log(metrics.getMetric('lowestPriceOver2'));

0 commit comments

Comments
 (0)