Skip to content

Commit c2bb090

Browse files
committed
[null] Small steps
1 parent 25a49d8 commit c2bb090

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/common/other.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export const isInstanceOf = (
3737
export const isUndefined = (thing: unknown): thing is undefined | null =>
3838
thing == undefined;
3939

40+
export const isNull = (thing: unknown): thing is null => thing == null;
41+
4042
export const ifNotUndefined = <Value, Return>(
4143
value: Value | null | undefined,
4244
then: (value: Value) => Return,

src/persisters/common/database/sqlite.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import type {
99
} from '../../../@types/persisters/index.d.ts';
1010
import {collValues} from '../../../common/coll.ts';
1111
import {IdObj} from '../../../common/obj.ts';
12-
import {startInterval, stopInterval, tryCatch} from '../../../common/other.ts';
12+
import {
13+
isNull,
14+
startInterval,
15+
stopInterval,
16+
tryCatch,
17+
} from '../../../common/other.ts';
1318
import {EMPTY_STRING} from '../../../common/strings.ts';
1419
import {
1520
DATA_VERSION,
@@ -59,7 +64,7 @@ export const createCustomSqlitePersister = <
5964
const addPersisterListener = (
6065
listener: PersisterListener<Persist>,
6166
): (() => void) => {
62-
let interval: NodeJS.Timeout;
67+
let interval: number;
6368

6469
const startPolling = () =>
6570
(interval = startInterval(
@@ -71,7 +76,7 @@ export const createCustomSqlitePersister = <
7176
` ${DATA_VERSION} d,${SCHEMA_VERSION} s,TOTAL_CHANGES() c FROM ${PRAGMA}${DATA_VERSION} JOIN ${PRAGMA}${SCHEMA_VERSION}`,
7277
)) as [IdObj<number>];
7378
if (d != dataVersion || s != schemaVersion || c != totalChanges) {
74-
if (dataVersion != null) {
79+
if (!isNull(dataVersion)) {
7580
listener();
7681
}
7782
dataVersion = d;

src/ui-react-inspector/actions/common.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import type {
88
ValuesProps,
99
} from '../../@types/ui-react/index.d.ts';
1010
import {useCallback, useEffect, useState} from '../../common/react.ts';
11+
import { isUndefined
12+
13+
14+
} from '../../common/other.ts';
1115

1216
export type OnDoneProp = {readonly onDone: () => void};
1317

@@ -31,6 +35,8 @@ export const getNewIdFromSuggestedId = (
3135

3236
export const ConfirmableActions = <
3337
Props extends TableProps | RowProps | CellProps | ValuesProps | ValueProps,
38+
39+
3440
>({
3541
actions,
3642
...props
@@ -41,13 +47,13 @@ export const ConfirmableActions = <
4147
component: ComponentType<OnDoneProp & Props>,
4248
][];
4349
} & Props) => {
44-
const [confirming, setConfirming] = useState<number | null>();
45-
const handleDone = useCallback(() => setConfirming(null), []);
50+
const [confirming, setConfirming] = useState<number | undefined>();
51+
const handleDone = useCallback(() => setConfirming(undefined), []);
4652

4753
useEffect(() => {
48-
if (confirming != null) {
54+
if (!isUndefined(confirming)) {
4955
const handleKeyDown = (e: KeyboardEvent) => {
50-
if (confirming != null && e.key === 'Escape') {
56+
if (!isUndefined(confirming) && e.key === 'Escape') {
5157
e.preventDefault();
5258
handleDone();
5359
}
@@ -57,7 +63,7 @@ export const ConfirmableActions = <
5763
}
5864
}, [confirming, handleDone]);
5965

60-
if (confirming != null) {
66+
if (!isUndefined(confirming)) {
6167
const [, , Component] = actions[confirming];
6268
return (
6369
<>

0 commit comments

Comments
 (0)