Skip to content

Commit 4c2a1f0

Browse files
committed
enhance: MemoCache.query returns {data, paths} just like denormalize
1 parent 7d8eef9 commit 4c2a1f0

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

packages/core/src/controller/Controller.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ export default class Controller<
589589
.slice(0, rest.length - 1)
590590
.map(ensurePojo) as SchemaArgs<S>;
591591

592-
return this.memo.query(schema, args, state);
592+
const { data } = this.memo.query(schema, args, state);
593+
return typeof data === 'symbol' ? undefined : (data as any);
593594
}
594595

595596
/**
@@ -612,25 +613,8 @@ export default class Controller<
612613
.slice(0, rest.length - 1)
613614
.map(ensurePojo) as SchemaArgs<S>;
614615

615-
// TODO: breaking: Switch back to this.memo.query(schema, args, state.entities as any, state.indexes) to do
616-
// this logic
617-
const input = this.memo.buildQueryKey(
618-
schema,
619-
args,
620-
state,
621-
JSON.stringify(args),
622-
);
616+
const { data, paths } = this.memo.query(schema, args, state);
623617

624-
if (!input) {
625-
return { data: undefined, countRef: () => () => undefined };
626-
}
627-
628-
const { data, paths } = this.memo.denormalize(
629-
schema,
630-
input,
631-
state.entities,
632-
args,
633-
);
634618
return {
635619
data: typeof data === 'symbol' ? undefined : (data as any),
636620
countRef: this.gcPolicy.createCountRef({ paths }),

packages/normalizr/src/memo/MemoCache.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ export default class MemoCache {
7171
state: StateInterface,
7272
// NOTE: different orders can result in cache busting here; but since it's just a perf penalty we will allow for now
7373
argsKey: string = JSON.stringify(args),
74-
): DenormalizeNullable<S> | undefined {
74+
): {
75+
data: DenormalizeNullable<S> | symbol;
76+
paths: EntityPath[];
77+
} {
7578
const input = this.buildQueryKey(schema, args, state, argsKey);
7679

7780
if (!input) {
78-
return;
81+
return { data: undefined as any, paths: [] };
7982
}
8083

81-
const { data } = this.denormalize(schema, input, state.entities, args);
82-
return typeof data === 'symbol' ? undefined : (data as any);
84+
return this.denormalize(schema, input, state.entities, args);
8385
}
8486

8587
buildQueryKey<S extends Schema>(

0 commit comments

Comments
 (0)