Skip to content

Commit efdf112

Browse files
committed
[hygiene] New deps and React optimization
1 parent f044ae2 commit efdf112

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinybase",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"author": "jamesgpearce",
55
"repository": "github:tinyplex/tinybase",
66
"license": "MIT",
@@ -84,7 +84,7 @@
8484
"@types/jest": "^29.4.0",
8585
"@types/jest-environment-puppeteer": "^5.0.3",
8686
"@types/less": "^3.0.3",
87-
"@types/node": "^18.14.0",
87+
"@types/node": "^18.14.1",
8888
"@types/puppeteer": "^5.4.7",
8989
"@types/react": "^18.0.28",
9090
"@types/react-dom": "^18.0.11",

src/ui-react/common.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ const useThing = <
5454
id: Id | undefined,
5555
offset: number,
5656
): Thing | undefined => {
57-
const thingsAndThingsById = useContext(Context);
57+
const contextValue = useContext(Context);
5858
return (
5959
isUndefined(id)
60-
? thingsAndThingsById[offset]
61-
: objGet(thingsAndThingsById[offset + 1] as IdObj<Thing>, id)
60+
? contextValue[offset]
61+
: isString(id)
62+
? objGet(contextValue[offset + 1] as IdObj<Thing>, id)
63+
: id
6264
) as Thing;
6365
};
6466

@@ -75,10 +77,9 @@ const useThingOrThingId = <
7577
offset: number,
7678
): Thing | undefined => {
7779
const thing = useThing(thingOrThingId as Id, offset);
78-
if (isUndefined(thingOrThingId) || isString(thingOrThingId)) {
79-
return thing as Thing | undefined;
80-
}
81-
return thingOrThingId as Thing;
80+
return isUndefined(thingOrThingId) || isString(thingOrThingId)
81+
? (thing as Thing | undefined)
82+
: (thingOrThingId as Thing);
8283
};
8384

8485
export const useStore: typeof useStoreDecl = (id?: Id): Store | undefined =>

src/ui-react/components.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,23 @@ export const Provider: typeof ProviderDecl = ({
241241
checkpointsById,
242242
children,
243243
}: ProviderProps & {children: React.ReactNode}): any => {
244-
const thingsOrThingsId = useContext(Context);
244+
const parentValue = useContext(Context);
245245
return (
246246
<Context.Provider
247247
value={useMemo(
248248
() => [
249-
store ?? thingsOrThingsId[0],
250-
{...thingsOrThingsId[1], ...storesById},
251-
metrics ?? thingsOrThingsId[2],
252-
{...thingsOrThingsId[3], ...metricsById},
253-
indexes ?? thingsOrThingsId[4],
254-
{...thingsOrThingsId[5], ...indexesById},
255-
relationships ?? thingsOrThingsId[6],
256-
{...thingsOrThingsId[7], ...relationshipsById},
257-
queries ?? thingsOrThingsId[8],
258-
{...thingsOrThingsId[9], ...queriesById},
259-
checkpoints ?? thingsOrThingsId[10],
260-
{...thingsOrThingsId[11], ...checkpointsById},
249+
store ?? parentValue[0],
250+
{...parentValue[1], ...storesById},
251+
metrics ?? parentValue[2],
252+
{...parentValue[3], ...metricsById},
253+
indexes ?? parentValue[4],
254+
{...parentValue[5], ...indexesById},
255+
relationships ?? parentValue[6],
256+
{...parentValue[7], ...relationshipsById},
257+
queries ?? parentValue[8],
258+
{...parentValue[9], ...queriesById},
259+
checkpoints ?? parentValue[10],
260+
{...parentValue[11], ...checkpointsById},
261261
],
262262
[
263263
store,
@@ -272,7 +272,7 @@ export const Provider: typeof ProviderDecl = ({
272272
queriesById,
273273
checkpoints,
274274
checkpointsById,
275-
thingsOrThingsId,
275+
parentValue,
276276
],
277277
)}
278278
>

0 commit comments

Comments
 (0)