Skip to content

Commit

Permalink
Get rid of NormalizedCacheFactory abstraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jun 12, 2018
1 parent 4621f4c commit 8200d31
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,6 @@ describe('writing to the store', () => {
selectionSet: def.selectionSet,
result: cloneDeep(result),
context: {
storeFactory: defaultNormalizedCacheFactory,
store: defaultNormalizedCacheFactory(),
variables,
dataIdFromObject: () => '5',
Expand Down
7 changes: 3 additions & 4 deletions packages/apollo-cache-inmemory/src/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const defaultConfig: ApolloReducerConfig = {
fragmentMatcher: new HeuristicFragmentMatcher(),
dataIdFromObject: defaultDataIdFromObject,
addTypename: true,
storeFactory: defaultNormalizedCacheFactory,
};

export function defaultDataIdFromObject(result: any): string | null {
Expand Down Expand Up @@ -69,7 +68,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
}

this.addTypename = this.config.addTypename;
this.data = this.config.storeFactory();
this.data = defaultNormalizedCacheFactory();
}

public restore(data: NormalizedCacheObject): this {
Expand All @@ -92,7 +91,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
}

return readQueryFromStore({
store: this.config.storeFactory(this.extract(query.optimistic)),
store: defaultNormalizedCacheFactory(this.extract(query.optimistic)),
query: this.transformDocument(query.query),
variables: query.variables,
rootId: query.rootId,
Expand All @@ -118,7 +117,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {

public diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T> {
return diffQueryAgainstStore({
store: this.config.storeFactory(this.extract(query.optimistic)),
store: defaultNormalizedCacheFactory(this.extract(query.optimistic)),
query: this.transformDocument(query.query),
variables: query.variables,
returnPartialData: query.returnPartialData,
Expand Down
5 changes: 0 additions & 5 deletions packages/apollo-cache-inmemory/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ export interface StoreObject {
[storeFieldKey: string]: StoreValue;
}

export type NormalizedCacheFactory = (
seed?: NormalizedCacheObject,
) => NormalizedCache;

export type OptimisticStoreItem = {
id: string;
data: NormalizedCacheObject;
Expand All @@ -68,7 +64,6 @@ export type ApolloReducerConfig = {
fragmentMatcher?: FragmentMatcherInterface;
addTypename?: boolean;
cacheRedirects?: CacheResolverMap;
storeFactory?: NormalizedCacheFactory;
};

export type ReadStoreContext = {
Expand Down
12 changes: 2 additions & 10 deletions packages/apollo-cache-inmemory/src/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { defaultNormalizedCacheFactory, ObjectCache } from './objectCache';
import {
IdGetter,
NormalizedCache,
NormalizedCacheFactory,
ReadStoreContext,
StoreObject,
} from './types';
Expand Down Expand Up @@ -72,16 +71,14 @@ export function enhanceErrorWithDocument(error: Error, document: DocumentNode) {
export function writeQueryToStore({
query,
result,
storeFactory = defaultNormalizedCacheFactory,
store = storeFactory(),
store = defaultNormalizedCacheFactory(),
variables,
dataIdFromObject,
fragmentMatcherFunction,
}: {
query: DocumentNode;
result: Object;
store?: NormalizedCache;
storeFactory?: NormalizedCacheFactory;
variables?: Object;
dataIdFromObject?: IdGetter;
fragmentMatcherFunction?: FragmentMatcher;
Expand All @@ -95,7 +92,6 @@ export function writeQueryToStore({
selectionSet: queryDefinition.selectionSet,
context: {
store,
storeFactory,
processedData: {},
variables: assign({}, getDefaultValues(queryDefinition), variables),
dataIdFromObject,
Expand All @@ -110,7 +106,6 @@ export function writeQueryToStore({

export type WriteContext = {
readonly store: NormalizedCache;
readonly storeFactory: NormalizedCacheFactory;
readonly processedData?: { [x: string]: FieldNode[] };
readonly variables?: any;
readonly dataIdFromObject?: IdGetter;
Expand All @@ -122,8 +117,7 @@ export function writeResultToStore({
dataId,
result,
document,
storeFactory = defaultNormalizedCacheFactory,
store = storeFactory(),
store = defaultNormalizedCacheFactory(),
variables,
dataIdFromObject,
fragmentMatcherFunction,
Expand All @@ -132,7 +126,6 @@ export function writeResultToStore({
result: any;
document: DocumentNode;
store?: NormalizedCache;
storeFactory?: NormalizedCacheFactory;
variables?: Object;
dataIdFromObject?: IdGetter;
fragmentMatcherFunction?: FragmentMatcher;
Expand All @@ -147,7 +140,6 @@ export function writeResultToStore({
selectionSet: operationDefinition.selectionSet,
context: {
store,
storeFactory,
processedData: {},
variables: assign({}, getDefaultValues(operationDefinition), variables),
dataIdFromObject,
Expand Down

0 comments on commit 8200d31

Please sign in to comment.