Skip to content

Commit cd827b6

Browse files
committed
enhance: MemoCache.query returns {data, paths} just like denormalize
1 parent 679d76a commit cd827b6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/core/src/controller/Controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,13 @@ export default class Controller<
545545
.slice(0, rest.length - 1)
546546
.map(ensurePojo) as SchemaArgs<S>;
547547

548-
return this.memo.query(schema, args, state.entities as any, state.indexes);
548+
const { data } = this.memo.query(
549+
schema,
550+
args,
551+
state.entities as any,
552+
state.indexes,
553+
);
554+
return typeof data === 'symbol' ? undefined : (data as any);
549555
}
550556

551557
private getSchemaResponse<T>(

packages/normalizr/src/memo/MemoCache.ts

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

7578
if (!input) {
76-
return;
79+
return { data: undefined as any, paths: [] };
7780
}
7881

79-
const { data } = this.denormalize(schema, input, entities, args);
80-
return typeof data === 'symbol' ? undefined : (data as any);
82+
return this.denormalize(schema, input, entities, args);
8183
}
8284

8385
buildQueryKey<S extends Schema>(

0 commit comments

Comments
 (0)