Skip to content

Commit 3604f22

Browse files
committed
[hygiene] objToArray -> objMap
1 parent 97c06cf commit 3604f22

File tree

11 files changed

+38
-44
lines changed

11 files changed

+38
-44
lines changed

src/cli/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {createTools} from '../tools/index.ts';
1010
import {fileURLToPath} from 'url';
1111
import {isArray} from '../common/other.ts';
1212
import {jsonParse} from '../common/json.ts';
13-
import {objToArray} from '../common/obj.ts';
13+
import {objMap} from '../common/obj.ts';
1414

1515
const FILE_ERROR = 'provide a valid schemaFile, storeName, and outputDir';
1616

@@ -46,7 +46,7 @@ const getTools = (schemaFile: string) => {
4646

4747
const help = () => {
4848
log('', 'tinybase <command>', '', 'Usage:', '');
49-
objToArray(commands, ([, args, help], command) =>
49+
objMap(commands, ([, args, help], command) =>
5050
log(` tinybase ${command} ${args}`, ` - ${help}`, ''),
5151
);
5252
log('See also http://tinybase.org/guides/developer-tools/command-line/', '');

src/common/map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {IdObj, objHas, objIsEmpty, objToArray} from './obj.ts';
1+
import {IdObj, objHas, objIsEmpty, objMap} from './obj.ts';
22
import {collDel, collForEach, collHas, collIsEmpty} from './coll.ts';
33
import {ifNotUndefined, isUndefined, size} from './other.ts';
44
import type {Id} from '../@types/common/index.d.ts';
@@ -59,7 +59,7 @@ export const mapMatch = <MapValue, ObjValue>(
5959
set: (map: IdMap<MapValue>, id: Id, value: ObjValue) => void,
6060
del: (map: IdMap<MapValue>, id: Id) => void = mapSet,
6161
): IdMap<MapValue> => {
62-
objToArray(obj, (value, id) => set(map, id, value));
62+
objMap(obj, (value, id) => set(map, id, value));
6363
mapForEach(map, (id) => (objHas(obj, id) ? 0 : del(map, id)));
6464
return map;
6565
};

src/common/obj.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const objValidate = (
110110
onInvalidObj?.();
111111
return false;
112112
}
113-
objToArray(obj, (child, id) => {
113+
objForEach(obj, (child, id) => {
114114
if (!validateChild(child, id)) {
115115
objDel(obj, id);
116116
}

src/mergeable-store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import {
3838
objForEach,
3939
objFreeze,
4040
objHas,
41+
objMap,
4142
objNew,
42-
objToArray,
4343
objValidate,
4444
} from '../common/obj.ts';
4545
import {IdSet, IdSet3, setAdd, setNew} from '../common/set.ts';
@@ -631,7 +631,7 @@ export const createMergeableStore = ((uniqueId?: Id): MergeableStore => {
631631
valueChanged,
632632
);
633633

634-
objToArray(
634+
objMap(
635635
store as IdObj<any>,
636636
(method, name) =>
637637
(mergeableStore[name] =

src/persisters/common/database/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const getCommandFunctions = (
120120
partial = false,
121121
): Promise<void> => {
122122
const settingColumnNameSet = setNew<string>();
123-
objToArray(content ?? {}, (contentRow) =>
123+
objMap(content ?? {}, (contentRow) =>
124124
arrayMap(objIds(contentRow ?? {}), (cellOrValueId) =>
125125
setAdd(settingColumnNameSet, cellOrValueId),
126126
),
@@ -254,7 +254,7 @@ export const getCommandFunctions = (
254254
);
255255
const rows: {[id: string]: any[]} = {};
256256
const deleteRowIds: string[] = [];
257-
objToArray(content ?? {}, (row, rowId) => {
257+
objMap(content ?? {}, (row, rowId) => {
258258
rows[rowId] = arrayMap(changingColumnNames, (cellId) =>
259259
encode ? encode(row?.[cellId]) : row?.[cellId],
260260
);

src/persisters/common/database/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {IdMap, mapNew, mapSet} from '../../../common/map.ts';
22
import {
33
IdObj,
4+
objMap,
45
objMerge,
56
objSize,
6-
objToArray,
77
objValues,
88
} from '../../../common/obj.ts';
99
import {isString, isUndefined, slice} from '../../../common/other.ts';
@@ -77,7 +77,7 @@ const getDefaultedTabularConfigMap = (
7777
then: (id: string, firstValue: string) => void,
7878
): IdMap<any[]> => {
7979
const configMap = mapNew<Id, any[]>();
80-
objToArray(configsObj, (configObj, id) => {
80+
objMap(configsObj, (configObj, id) => {
8181
const defaultedConfig = slice(
8282
objValues(
8383
objMerge(

src/persisters/persister-automerge/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
objGet,
1111
objHas,
1212
objIsEmpty,
13+
objMap,
1314
objNew,
1415
objSize,
15-
objToArray,
1616
} from '../../common/obj.ts';
1717
import {ifNotUndefined, isUndefined} from '../../common/other.ts';
1818
import {DocHandle} from '@automerge/automerge-repo';
@@ -48,23 +48,23 @@ const applyChangesToDoc = (
4848
let changesFailed = 1;
4949
ifNotUndefined(changes, ([cellChanges, valueChanges]) => {
5050
changesFailed = 0;
51-
objToArray(cellChanges, (table, tableId) =>
51+
objMap(cellChanges, (table, tableId) =>
5252
changesFailed
5353
? 0
5454
: isUndefined(table)
5555
? objDel(docTables, tableId)
5656
: ifNotUndefined(
5757
docTables[tableId],
5858
(docTable) =>
59-
objToArray(table, (row, rowId) =>
59+
objMap(table, (row, rowId) =>
6060
changesFailed
6161
? 0
6262
: isUndefined(row)
6363
? objDel(docTable, rowId)
6464
: ifNotUndefined(
6565
objGet(docTable, rowId),
6666
(docRow: any) =>
67-
objToArray(row, (cell, cellId) =>
67+
objMap(row, (cell, cellId) =>
6868
isUndefined(cell)
6969
? objDel(docRow, cellId)
7070
: (docRow[cellId] = cell),
@@ -75,7 +75,7 @@ const applyChangesToDoc = (
7575
changesDidFail,
7676
),
7777
);
78-
objToArray(valueChanges, (value, valueId) =>
78+
objMap(valueChanges, (value, valueId) =>
7979
changesFailed
8080
? 0
8181
: isUndefined(value)
@@ -113,12 +113,12 @@ const docObjMatch = (
113113
? docObjOrParent
114114
: objEnsure(docObjOrParent, idInParent, () => ({}));
115115
let changed: 1 | undefined;
116-
objToArray(obj, (value, id) => {
116+
objMap(obj, (value, id) => {
117117
if (set(docObj, id, value)) {
118118
changed = 1;
119119
}
120120
});
121-
objToArray(docObj, (_: any, id: Id) => {
121+
objMap(docObj, (_: any, id: Id) => {
122122
if (!objHas(obj, id)) {
123123
objDel(docObj, id);
124124
changed = 1;

src/persisters/persister-yjs/index.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import type {
66
Tables,
77
Values,
88
} from '../../@types/store/index.d.ts';
9-
import {
10-
IdObj,
11-
objEnsure,
12-
objHas,
13-
objNew,
14-
objToArray,
15-
} from '../../common/obj.ts';
9+
import {IdObj, objEnsure, objHas, objMap, objNew} from '../../common/obj.ts';
1610
import {T, TINYBASE, V} from '../../common/strings.ts';
1711
import {Doc as YDoc, type YEvent, Map as YMap} from 'yjs';
1812
import type {
@@ -102,23 +96,23 @@ const applyChangesToYDoc = (
10296
let changesFailed = 1;
10397
ifNotUndefined(changes, ([cellChanges, valueChanges]) => {
10498
changesFailed = 0;
105-
objToArray(cellChanges, (table, tableId) =>
99+
objMap(cellChanges, (table, tableId) =>
106100
changesFailed
107101
? 0
108102
: isUndefined(table)
109103
? yTables.delete(tableId)
110104
: ifNotUndefined(
111105
yTables.get(tableId),
112106
(yTable) =>
113-
objToArray(table, (row, rowId) =>
107+
objMap(table, (row, rowId) =>
114108
changesFailed
115109
? 0
116110
: isUndefined(row)
117111
? yTable.delete(rowId)
118112
: ifNotUndefined(
119113
yTable.get(rowId),
120114
(yRow) =>
121-
objToArray(row, (cell, cellId) =>
115+
objMap(row, (cell, cellId) =>
122116
isUndefined(cell)
123117
? yRow.delete(cellId)
124118
: yRow.set(cellId, cell),
@@ -129,7 +123,7 @@ const applyChangesToYDoc = (
129123
changesDidFail,
130124
),
131125
);
132-
objToArray(valueChanges, (value, valueId) =>
126+
objMap(valueChanges, (value, valueId) =>
133127
changesFailed
134128
? 0
135129
: isUndefined(value)
@@ -168,7 +162,7 @@ const yMapMatch = (
168162
: (yMapOrParent.get(idInParent) ??
169163
yMapOrParent.set(idInParent, new YMap()));
170164
let changed: 1 | undefined;
171-
objToArray(obj, (value, id) => {
165+
objMap(obj, (value, id) => {
172166
if (set(yMap, id, value)) {
173167
changed = 1;
174168
}

src/queries/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import {
7575
size,
7676
slice,
7777
} from '../common/other.ts';
78-
import {objFreeze, objToArray} from '../common/obj.ts';
78+
import {objFreeze, objMap} from '../common/obj.ts';
7979

8080
type StoreWithPrivateMethods = Store & {
8181
createStore: () => Store;
@@ -614,7 +614,7 @@ export const createQueries = getCreateFunction((store: Store): Queries => {
614614
getListenerStats,
615615
};
616616

617-
objToArray(
617+
objMap(
618618
{
619619
[TABLE]: [1, 1],
620620
[TABLE + CELL_IDS]: [0, 1],

src/store/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ import {
128128
objFreeze,
129129
objHas,
130130
objIsEmpty,
131-
objToArray,
131+
objMap,
132132
objValidate,
133133
} from '../common/obj.ts';
134134
import {defaultSorter} from '../common/index.ts';
@@ -1131,7 +1131,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
11311131
(tableId, rowId) => {
11321132
if (validateRow(tableId, rowId, partialRow, 1)) {
11331133
const table = getOrCreateTable(tableId);
1134-
objToArray(partialRow, (cell, cellId) =>
1134+
objMap(partialRow, (cell, cellId) =>
11351135
setCellIntoDefaultRow(tableId, table, rowId, cellId, cell as Cell),
11361136
);
11371137
}
@@ -1177,7 +1177,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
11771177
const setPartialValues = (partialValues: Values): Store =>
11781178
fluentTransaction(() =>
11791179
validateValues(partialValues, 1)
1180-
? objToArray(partialValues, (value, valueId) =>
1180+
? objMap(partialValues, (value, valueId) =>
11811181
setValidValue(valueId, value as Value),
11821182
)
11831183
: 0,
@@ -1198,13 +1198,13 @@ export const createStore: typeof createStoreDecl = (): Store => {
11981198

11991199
const applyChanges = (changes: Changes): Store =>
12001200
fluentTransaction(() => {
1201-
objToArray(changes[0], (table, tableId) =>
1201+
objMap(changes[0], (table, tableId) =>
12021202
isUndefined(table)
12031203
? delTable(tableId)
1204-
: objToArray(table, (row, rowId) =>
1204+
: objMap(table, (row, rowId) =>
12051205
isUndefined(row)
12061206
? delRow(tableId, rowId)
1207-
: objToArray(row, (cell, cellId) =>
1207+
: objMap(row, (cell, cellId) =>
12081208
setOrDelCell(
12091209
store,
12101210
tableId,
@@ -1215,7 +1215,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
12151215
),
12161216
),
12171217
);
1218-
objToArray(changes[1], (value, valueId) =>
1218+
objMap(changes[1], (value, valueId) =>
12191219
setOrDelValue(store, valueId, value as ValueOrUndefined),
12201220
);
12211221
});
@@ -1716,7 +1716,7 @@ export const createStore: typeof createStoreDecl = (): Store => {
17161716
};
17171717

17181718
// and now for some gentle meta-programming
1719-
objToArray(
1719+
objMap(
17201720
{
17211721
[HAS + TABLES]: [0, hasTablesListeners, [], () => [hasTables()]],
17221722
[TABLES]: [0, tablesListeners],

0 commit comments

Comments
 (0)