Skip to content

Commit c61965c

Browse files
committed
[nulls] More progess
1 parent c2bb090 commit c61965c

7 files changed

Lines changed: 18 additions & 13 deletions

File tree

coverage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tests":7143,"assertions":32130,"lines":{"total":2326,"covered":2326,"skipped":0,"pct":100},"statements":{"total":2515,"covered":2515,"skipped":0,"pct":100},"functions":{"total":1005,"covered":1005,"skipped":0,"pct":100},"branches":{"total":876,"covered":876,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
1+
{"tests":7143,"assertions":32130,"lines":{"total":2333,"covered":2332,"skipped":0,"pct":99.95},"statements":{"total":2521,"covered":2520,"skipped":0,"pct":99.96},"functions":{"total":1006,"covered":1006,"skipped":0,"pct":100},"branches":{"total":881,"covered":880,"skipped":0,"pct":99.88},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}

src/common/listeners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import type {
5858
import {arrayForEach, arrayPush} from './array.ts';
5959
import {collDel, collForEach, collIsEmpty} from './coll.ts';
6060
import {IdMap, Node, mapGet, mapNew, mapSet, visitTree} from './map.ts';
61-
import {ifNotUndefined, isUndefined, size} from './other.ts';
61+
import {ifNotUndefined, isNull, size} from './other.ts';
6262
import {getPoolFunctions} from './pool.ts';
6363
import {IdSet, setAdd, setNew} from './set.ts';
6464
import {EMPTY_STRING} from './strings.ts';
@@ -226,7 +226,7 @@ export const getListenerFunctions = (
226226
const index = size(ids);
227227
if (index == size(path)) {
228228
(listener as any)(thing, ...ids, ...extraArgsGetter(ids));
229-
} else if (isUndefined(path[index])) {
229+
} else if (isNull(path[index])) {
230230
arrayForEach(pathGetters[index]?.(...ids) ?? [], (id) =>
231231
callWithIds(...ids, id),
232232
);

src/common/map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const mapSet = <Key, Value>(
3737
key: Key,
3838
value?: Value,
3939
): Map<Key, Value> | undefined =>
40-
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
40+
value === undefined ? (collDel(map, key), map) : map?.set(key, value);
4141

4242
export const mapEnsure = <Key, Value>(
4343
map: Map<Key, Value>,

src/common/obj.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {Id} from '../@types/common/index.d.ts';
22
import {arrayEvery, arrayForEach, arrayMap} from './array.ts';
3-
import {ifNotUndefined, isUndefined, size} from './other.ts';
3+
import {ifNotUndefined, isNull, isUndefined, size} from './other.ts';
44

55
export type IdObj<Value> = {[id: string]: Value};
66
export type IdObj2<Value> = IdObj<IdObj<Value>>;
@@ -104,6 +104,7 @@ export const objValidate = (
104104
emptyIsValid: 0 | 1 = 0,
105105
): boolean => {
106106
if (
107+
isNull(obj) ||
107108
isUndefined(obj) ||
108109
!isObject(obj) ||
109110
(!emptyIsValid && objIsEmpty(obj)) ||

src/common/other.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ export const isInstanceOf = (
3434
cls: MapConstructor | SetConstructor | ObjectConstructor,
3535
): boolean => thing instanceof cls;
3636

37-
export const isUndefined = (thing: unknown): thing is undefined | null =>
38-
thing == undefined;
37+
export const isUndefined = (thing: unknown): thing is undefined | null => {
38+
if (thing === null) {
39+
console.log('isUndefined called with null from:', new Error().stack);
40+
}
41+
return thing == undefined;
42+
};
3943

4044
export const isNull = (thing: unknown): thing is null => thing == null;
4145

src/queries/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
199199
resetPreStores(queryId);
200200

201201
const selectEntries: [Id, SelectClause][] = [];
202-
const joinEntries: [IdOrNull, JoinClause][] = [
203-
[null, [tableId, null, null, [], mapNew()]],
202+
const joinEntries: [Id | undefined, JoinClause][] = [
203+
[undefined, [tableId, null, null, [], mapNew()]],
204204
];
205205
const wheres: WhereClause[] = [];
206206
const groupEntries: [Id, GroupClause][] = [];
@@ -226,7 +226,7 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
226226
arg2?: Id | ((getCell: GetCell, rowId: Id) => Id | undefined),
227227
) => {
228228
const fromIntermediateJoinedTableId =
229-
isUndefined(arg2) || isFunction(arg1) ? null : arg1;
229+
isUndefined(arg2) || isFunction(arg1) ? undefined : arg1;
230230
const onArg = isUndefined(fromIntermediateJoinedTableId) ? arg1 : arg2;
231231
const joinEntry: [Id, JoinClause] = [
232232
joinedTableId,
@@ -296,7 +296,7 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
296296
if (collIsEmpty(selects)) {
297297
return queries;
298298
}
299-
const joins: Map<IdOrNull, JoinClause> = mapNew(joinEntries);
299+
const joins: Map<Id | undefined, JoinClause> = mapNew(joinEntries);
300300
mapForEach(joins, (asTableId, [, fromAsTableId]) =>
301301
ifNotUndefined(mapGet(joins, fromAsTableId), ({3: toAsTableIds}) =>
302302
isUndefined(asTableId) ? 0 : arrayPush(toAsTableIds, asTableId),
@@ -542,7 +542,7 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
542542
writeSelectRow(rootRowId);
543543
};
544544

545-
const {3: joinedTableIds} = mapGet(joins, null) as JoinClause;
545+
const {3: joinedTableIds} = mapGet(joins, undefined) as JoinClause;
546546
selectJoinWhereStore.transaction(() =>
547547
addStoreListeners(
548548
queryId,

src/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
628628
mapSet(
629629
cellIds,
630630
cellId,
631-
count != -addedOrRemoved ? count + addedOrRemoved : null,
631+
count != -addedOrRemoved ? count + addedOrRemoved : undefined,
632632
);
633633

634634
idsChanged(

0 commit comments

Comments
 (0)