Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: MemoCache.query returns {data, paths} just like denormalize #3372

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/core/src/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,13 @@ export default class Controller<
.slice(0, rest.length - 1)
.map(ensurePojo) as SchemaArgs<S>;

return this.memo.query(schema, args, state.entities as any, state.indexes);
const { data } = this.memo.query(
schema,
args,
state.entities as any,
state.indexes,
);
return typeof data === 'symbol' ? undefined : (data as any);
}

private getSchemaResponse<T>(
Expand Down
10 changes: 6 additions & 4 deletions packages/normalizr/src/memo/MemoCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ export default class MemoCache {
},
// NOTE: different orders can result in cache busting here; but since it's just a perf penalty we will allow for now
argsKey: string = JSON.stringify(args),
): DenormalizeNullable<S> | undefined {
): {
data: DenormalizeNullable<S> | symbol;
paths: EntityPath[];
} {
const input = this.buildQueryKey(schema, args, entities, indexes, argsKey);

if (!input) {
return;
return { data: undefined as any, paths: [] };
}

const { data } = this.denormalize(schema, input, entities, args);
return typeof data === 'symbol' ? undefined : (data as any);
return this.denormalize(schema, input, entities, args);
}

buildQueryKey<S extends Schema>(
Expand Down
Loading