Skip to content

Commit

Permalink
Fix apollo-cache-inmemory in IE11
Browse files Browse the repository at this point in the history
In IE11, Map.prototype.set is not spec-compliant and returns undefined.
This commit removes the chained calls on Map to avoid the TypeError.
  • Loading branch information
ooflorent committed Oct 16, 2018
1 parent f927219 commit f0258f3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/apollo-cache-inmemory/src/optimism.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
declare function require(id: string): any;

export type OptimisticWrapperFunction<
T = (...args: any[]) => any,
> = T & {
export type OptimisticWrapperFunction<T = (...args: any[]) => any> = T & {
// The .dirty(...) method of an optimistic function takes exactly the same
// parameter types as the original function.
dirty: T;
Expand All @@ -14,7 +12,9 @@ export type OptimisticWrapOptions = {
makeCacheKey?(...args: any[]): any;
};

const { wrap }: {
const {
wrap,
}: {
wrap<T>(
originalFunction: T,
options?: OptimisticWrapOptions,
Expand All @@ -40,7 +40,12 @@ export class CacheKeyNode<KeyType = object> {
}

getOrCreate(value: any): CacheKeyNode<KeyType> {
const map = this.children || (this.children = new Map);
return map.get(value) || map.set(value, new CacheKeyNode<KeyType>()).get(value);
const map = this.children || (this.children = new Map());
let node = map.get(value);
if (node === undefined) {
node = new CacheKeyNode<KeyType>();
map.set(value, node);
}
return node;
}
}

0 comments on commit f0258f3

Please sign in to comment.