Skip to content

Commit dd2647f

Browse files
committed
[null] Tidy up
1 parent cf354ba commit dd2647f

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

src/@types/common/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type ParameterizedCallback<Parameter> = (parameter?: Parameter) => void;
2121
export type Callback = () => void;
2222

2323
/// SortKey
24-
export type SortKey = string | number | boolean;
24+
export type SortKey = string | number | boolean | null;
2525

2626
/// GetNow
2727
export type GetNow = () => number;

src/common/cell.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import type {
66
} from '../@types/store/index.d.ts';
77
import {
88
isFiniteNumber,
9-
isNullish,
9+
isNull,
1010
isTypeStringOrBoolean,
1111
isUndefined,
1212
} from './other.ts';
1313
import {BOOLEAN, NUMBER, STRING, getTypeOf} from './strings.ts';
1414

15-
export type CellOrValueType = 'string' | 'number' | 'boolean';
15+
export type CellOrValueType = 'string' | 'number' | 'boolean' | 'null';
1616

1717
export const getCellOrValueType = (
1818
cellOrValue: any,
1919
): CellOrValueType | undefined => {
20-
if (isNullish(cellOrValue)) {
21-
return undefined;
20+
if (isNull(cellOrValue)) {
21+
return 'null';
2222
}
2323
const type = getTypeOf(cellOrValue);
2424
return isTypeStringOrBoolean(type) ||
@@ -27,8 +27,8 @@ export const getCellOrValueType = (
2727
: undefined;
2828
};
2929

30-
export const isCellOrValueOrNullOrUndefined = (cellOrValue: any): boolean =>
31-
isNullish(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
30+
export const isCellOrValueOrUndefined = (cellOrValue: any): boolean =>
31+
isUndefined(cellOrValue) || !isUndefined(getCellOrValueType(cellOrValue));
3232

3333
export const setOrDelCell = (
3434
store: Store,

src/mergeable-store/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
Store,
2323
ValueOrUndefined,
2424
} from '../@types/store/index.d.ts';
25-
import {isCellOrValueOrNullOrUndefined} from '../common/cell.ts';
25+
import {isCellOrValueOrUndefined} from '../common/cell.ts';
2626
import {collClear, collForEach} from '../common/coll.ts';
2727
import {
2828
addOrRemoveHash,
@@ -126,7 +126,7 @@ const validateMergeableContent = (
126126
objValidate(
127127
cellStamps,
128128
(cellStamp) =>
129-
stampValidate(cellStamp, isCellOrValueOrNullOrUndefined),
129+
stampValidate(cellStamp, isCellOrValueOrUndefined),
130130
undefined,
131131
1,
132132
),
@@ -142,7 +142,7 @@ const validateMergeableContent = (
142142
stampValidate(mergeableContent[1], (values) =>
143143
objValidate(
144144
values,
145-
(value) => stampValidate(value, isCellOrValueOrNullOrUndefined),
145+
(value) => stampValidate(value, isCellOrValueOrUndefined),
146146
undefined,
147147
1,
148148
),

src/store/index.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,19 @@ export const createStore: typeof createStoreDecl = (): Store => {
303303
? ifNotUndefined(
304304
mapGet(mapGet(tablesSchemaMap, tableId), cellId),
305305
(cellSchema) =>
306-
getCellOrValueType(cell) != cellSchema[TYPE]
307-
? cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
308-
: cell,
306+
isNull(cell)
307+
? cellSchema[ALLOW_NULL]
308+
? cell
309+
: cellInvalid(tableId, rowId, cellId, cell, cellSchema[DEFAULT])
310+
: getCellOrValueType(cell) == cellSchema[TYPE]
311+
? cell
312+
: cellInvalid(
313+
tableId,
314+
rowId,
315+
cellId,
316+
cell,
317+
cellSchema[DEFAULT],
318+
),
309319
() => cellInvalid(tableId, rowId, cellId, cell),
310320
)
311321
: isUndefined(getCellOrValueType(cell))
@@ -332,9 +342,13 @@ export const createStore: typeof createStoreDecl = (): Store => {
332342
? ifNotUndefined(
333343
mapGet(valuesSchemaMap, valueId),
334344
(valueSchema) =>
335-
getCellOrValueType(value) != valueSchema[TYPE]
336-
? valueInvalid(valueId, value, valueSchema[DEFAULT])
337-
: value,
345+
isNull(value)
346+
? valueSchema[ALLOW_NULL]
347+
? value
348+
: valueInvalid(valueId, value, valueSchema[DEFAULT])
349+
: getCellOrValueType(value) == valueSchema[TYPE]
350+
? value
351+
: valueInvalid(valueId, value, valueSchema[DEFAULT]),
338352
() => valueInvalid(valueId, value),
339353
)
340354
: isUndefined(getCellOrValueType(value))

0 commit comments

Comments
 (0)