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 authored and benjamn committed Oct 24, 2018
1 parent 18dfe93 commit 39778af
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/apollo-cache-inmemory/src/optimism.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare function require(id: string): any;

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

const { wrap }: {
const {
wrap,
}: {
wrap<T>(
originalFunction: T,
options?: OptimisticWrapOptions,
Expand All @@ -40,7 +42,11 @@ 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) {
map.set(value, node = new CacheKeyNode<KeyType>());
}
return node;
}
}

0 comments on commit 39778af

Please sign in to comment.