apollo-cache-router
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -20,2 +20,13 @@ (function (global, factory) { | ||
var apollo_cache_1 = require("apollo-cache"); | ||
var deepMerge = function (target, source) { | ||
for (var _i = 0, _a = Object.keys(source); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
if (!!target[key] && typeof target[key] === 'object') { | ||
deepMerge(target[key], source[key]); | ||
} | ||
else { | ||
target[key] = source[key]; | ||
} | ||
} | ||
}; | ||
var OverrideCache = (function (_super) { | ||
@@ -119,3 +130,5 @@ __extends(OverrideCache, _super); | ||
for (var idx = 0; idx < this.caches.length; idx++) { | ||
state['cache' + idx] = this.caches[idx].extract(optimistic); | ||
var cacheKey = '__cache' + idx; | ||
state[cacheKey] = this.caches[idx].extract(optimistic); | ||
deepMerge(state, state[cacheKey]); | ||
} | ||
@@ -126,3 +139,3 @@ return state; | ||
for (var idx = 0; idx < this.caches.length; idx++) { | ||
this.caches[idx].restore(serializedState['cache' + idx]); | ||
this.caches[idx].restore(serializedState['__cache' + idx]); | ||
} | ||
@@ -129,0 +142,0 @@ return this; |
@@ -14,2 +14,13 @@ "use strict"; | ||
var apollo_cache_1 = require("apollo-cache"); | ||
var deepMerge = function (target, source) { | ||
for (var _i = 0, _a = Object.keys(source); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
if (!!target[key] && typeof target[key] === 'object') { | ||
deepMerge(target[key], source[key]); | ||
} | ||
else { | ||
target[key] = source[key]; | ||
} | ||
} | ||
}; | ||
var OverrideCache = (function (_super) { | ||
@@ -113,3 +124,5 @@ __extends(OverrideCache, _super); | ||
for (var idx = 0; idx < this.caches.length; idx++) { | ||
state['cache' + idx] = this.caches[idx].extract(optimistic); | ||
var cacheKey = '__cache' + idx; | ||
state[cacheKey] = this.caches[idx].extract(optimistic); | ||
deepMerge(state, state[cacheKey]); | ||
} | ||
@@ -120,3 +133,3 @@ return state; | ||
for (var idx = 0; idx < this.caches.length; idx++) { | ||
this.caches[idx].restore(serializedState['cache' + idx]); | ||
this.caches[idx].restore(serializedState['__cache' + idx]); | ||
} | ||
@@ -123,0 +136,0 @@ return this; |
{ | ||
"name": "apollo-cache-router", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Apollo Cache Router", | ||
@@ -5,0 +5,0 @@ "main": "./lib/bundle.umd.js", |
import { ApolloCache, Cache, Transaction } from 'apollo-cache'; | ||
import { DocumentNode } from 'graphql'; | ||
const deepMerge = (target: any, source: any) => { | ||
for (const key of Object.keys(source)) { | ||
if (!!target[key] && typeof target[key] === 'object') { | ||
deepMerge(target[key], source[key]); | ||
} else { | ||
target[key] = source[key]; | ||
} | ||
} | ||
}; | ||
export interface OverrideOptions<TCache> { | ||
@@ -140,3 +150,5 @@ read?: <T>(query: Cache.ReadOptions) => T; | ||
for (let idx = 0; idx < this.caches.length; idx++) { | ||
state['cache' + idx] = this.caches[idx].extract(optimistic); | ||
const cacheKey = '__cache' + idx; | ||
state[cacheKey] = this.caches[idx].extract(optimistic); | ||
deepMerge(state, state[cacheKey]); | ||
} | ||
@@ -148,3 +160,3 @@ return state; | ||
for (let idx = 0; idx < this.caches.length; idx++) { | ||
this.caches[idx].restore(serializedState['cache' + idx]); | ||
this.caches[idx].restore(serializedState['__cache' + idx]); | ||
} | ||
@@ -151,0 +163,0 @@ return this; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52127
547