apollo-cache-inmemory
Advanced tools
Comparing version 1.3.0-beta.9 to 1.3.0-beta.10
@@ -856,3 +856,3 @@ (function (global, factory) { | ||
_this.optimistic = []; | ||
_this.watches = new Set(); | ||
_this.watches = []; | ||
_this.typenameDocumentCache = new WeakMap(); | ||
@@ -872,16 +872,2 @@ _this.silenceBroadcast = false; | ||
_this.storeReader = new StoreReader(); | ||
var cache = _this; | ||
var maybeBroadcastWatch = cache.maybeBroadcastWatch; | ||
_this.maybeBroadcastWatch = wrap(function (c) { | ||
return maybeBroadcastWatch.call(_this, c); | ||
}, { | ||
makeCacheKey: function (c) { | ||
if (c.optimistic && cache.optimistic.length > 0) { | ||
return; | ||
} | ||
if (cache.data instanceof DepTrackingCache) { | ||
return defaultMakeCacheKey(c.query, JSON.stringify(c.variables)); | ||
} | ||
} | ||
}); | ||
return _this; | ||
@@ -947,5 +933,5 @@ } | ||
var _this = this; | ||
this.watches.add(watch); | ||
this.watches.push(watch); | ||
return function () { | ||
_this.watches.delete(watch); | ||
_this.watches = _this.watches.filter(function (c) { return c !== watch; }); | ||
}; | ||
@@ -1040,14 +1026,15 @@ }; | ||
InMemoryCache.prototype.broadcastWatches = function () { | ||
if (!this.silenceBroadcast) { | ||
this.watches.forEach(this.maybeBroadcastWatch, this); | ||
} | ||
var _this = this; | ||
if (this.silenceBroadcast) | ||
return; | ||
this.watches.forEach(function (c) { | ||
var newData = _this.diff({ | ||
query: c.query, | ||
variables: c.variables, | ||
previousResult: c.previousResult && c.previousResult(), | ||
optimistic: c.optimistic, | ||
}); | ||
c.callback(newData); | ||
}); | ||
}; | ||
InMemoryCache.prototype.maybeBroadcastWatch = function (c) { | ||
c.callback(this.diff({ | ||
query: c.query, | ||
variables: c.variables, | ||
previousResult: c.previousResult && c.previousResult(), | ||
optimistic: c.optimistic, | ||
})); | ||
}; | ||
return InMemoryCache; | ||
@@ -1054,0 +1041,0 @@ }(apolloCache.ApolloCache)); |
@@ -32,4 +32,3 @@ import { DocumentNode } from 'graphql'; | ||
protected broadcastWatches(): void; | ||
private maybeBroadcastWatch; | ||
} | ||
//# sourceMappingURL=inMemoryCache.d.ts.map |
@@ -30,4 +30,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import { StoreReader } from './readFromStore'; | ||
import { defaultNormalizedCacheFactory, DepTrackingCache } from './depTrackingCache'; | ||
import { wrap, defaultMakeCacheKey } from "./optimism"; | ||
import { defaultNormalizedCacheFactory } from './depTrackingCache'; | ||
import { record } from './recordingCache'; | ||
@@ -56,3 +55,3 @@ var defaultConfig = { | ||
_this.optimistic = []; | ||
_this.watches = new Set(); | ||
_this.watches = []; | ||
_this.typenameDocumentCache = new WeakMap(); | ||
@@ -72,16 +71,2 @@ _this.silenceBroadcast = false; | ||
_this.storeReader = new StoreReader(); | ||
var cache = _this; | ||
var maybeBroadcastWatch = cache.maybeBroadcastWatch; | ||
_this.maybeBroadcastWatch = wrap(function (c) { | ||
return maybeBroadcastWatch.call(_this, c); | ||
}, { | ||
makeCacheKey: function (c) { | ||
if (c.optimistic && cache.optimistic.length > 0) { | ||
return; | ||
} | ||
if (cache.data instanceof DepTrackingCache) { | ||
return defaultMakeCacheKey(c.query, JSON.stringify(c.variables)); | ||
} | ||
} | ||
}); | ||
return _this; | ||
@@ -147,5 +132,5 @@ } | ||
var _this = this; | ||
this.watches.add(watch); | ||
this.watches.push(watch); | ||
return function () { | ||
_this.watches.delete(watch); | ||
_this.watches = _this.watches.filter(function (c) { return c !== watch; }); | ||
}; | ||
@@ -240,14 +225,15 @@ }; | ||
InMemoryCache.prototype.broadcastWatches = function () { | ||
if (!this.silenceBroadcast) { | ||
this.watches.forEach(this.maybeBroadcastWatch, this); | ||
} | ||
var _this = this; | ||
if (this.silenceBroadcast) | ||
return; | ||
this.watches.forEach(function (c) { | ||
var newData = _this.diff({ | ||
query: c.query, | ||
variables: c.variables, | ||
previousResult: c.previousResult && c.previousResult(), | ||
optimistic: c.optimistic, | ||
}); | ||
c.callback(newData); | ||
}); | ||
}; | ||
InMemoryCache.prototype.maybeBroadcastWatch = function (c) { | ||
c.callback(this.diff({ | ||
query: c.query, | ||
variables: c.variables, | ||
previousResult: c.previousResult && c.previousResult(), | ||
optimistic: c.optimistic, | ||
})); | ||
}; | ||
return InMemoryCache; | ||
@@ -254,0 +240,0 @@ }(ApolloCache)); |
{ | ||
"name": "apollo-cache-inmemory", | ||
"version": "1.3.0-beta.9", | ||
"version": "1.3.0-beta.10", | ||
"description": "Core abstract of Caching layer for Apollo Client", | ||
@@ -5,0 +5,0 @@ "author": "James Baxley <james@meteor.com>", |
@@ -18,7 +18,4 @@ import { DocumentNode } from 'graphql'; | ||
import { writeResultToStore } from './writeToStore'; | ||
import { StoreReader } from './readFromStore'; | ||
import { defaultNormalizedCacheFactory, DepTrackingCache } from './depTrackingCache'; | ||
import { wrap, defaultMakeCacheKey } from "./optimism"; | ||
import { defaultNormalizedCacheFactory } from './depTrackingCache'; | ||
import { record } from './recordingCache'; | ||
@@ -47,3 +44,3 @@ const defaultConfig: ApolloReducerConfig = { | ||
protected optimistic: OptimisticStoreItem[] = []; | ||
private watches = new Set<Cache.WatchOptions>(); | ||
private watches: Cache.WatchOptions[] = []; | ||
private addTypename: boolean; | ||
@@ -80,25 +77,2 @@ private typenameDocumentCache = new WeakMap<DocumentNode, DocumentNode>(); | ||
this.storeReader = new StoreReader(); | ||
const cache = this; | ||
const { maybeBroadcastWatch } = cache; | ||
this.maybeBroadcastWatch = wrap((c: Cache.WatchOptions) => { | ||
return maybeBroadcastWatch.call(this, c); | ||
}, { | ||
makeCacheKey(c: Cache.WatchOptions) { | ||
if (c.optimistic && cache.optimistic.length > 0) { | ||
// If we're reading optimistic data, it doesn't matter if this.data | ||
// is a DepTrackingCache, since it will be ignored. | ||
return; | ||
} | ||
if (cache.data instanceof DepTrackingCache) { | ||
// Return a cache key (thus enabling caching) only if we're currently | ||
// using a data store that can track cache dependencies. | ||
return defaultMakeCacheKey( | ||
c.query, | ||
JSON.stringify(c.variables), | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -171,6 +145,6 @@ | ||
public watch(watch: Cache.WatchOptions): () => void { | ||
this.watches.add(watch); | ||
this.watches.push(watch); | ||
return () => { | ||
this.watches.delete(watch); | ||
this.watches = this.watches.filter(c => c !== watch); | ||
}; | ||
@@ -311,19 +285,20 @@ } | ||
protected broadcastWatches() { | ||
if (!this.silenceBroadcast) { | ||
this.watches.forEach(this.maybeBroadcastWatch, this); | ||
} | ||
} | ||
// Skip this when silenced (like inside a transaction) | ||
if (this.silenceBroadcast) return; | ||
// This method is wrapped in the constructor so that it will be called only | ||
// if the data that would be broadcast has changed. | ||
private maybeBroadcastWatch(c: Cache.WatchOptions) { | ||
c.callback(this.diff({ | ||
query: c.query, | ||
variables: c.variables, | ||
// TODO: previousResult isn't in the types, so this will only work | ||
// with ObservableQuery which is in a different package. | ||
previousResult: (c as any).previousResult && c.previousResult(), | ||
optimistic: c.optimistic, | ||
})); | ||
// right now, we invalidate all queries whenever anything changes | ||
this.watches.forEach((c: Cache.WatchOptions) => { | ||
const newData = this.diff({ | ||
query: c.query, | ||
variables: c.variables, | ||
// TODO: previousResult isn't in the types - this will only work | ||
// with ObservableQuery which is in a different package | ||
previousResult: (c as any).previousResult && c.previousResult(), | ||
optimistic: c.optimistic, | ||
}); | ||
c.callback(newData); | ||
}); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
451060
9538