apollo-link-dedup
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -5,4 +5,10 @@ # Change log | ||
### 1.0.9 | ||
- Update apollo-link [#559](https://github.com/apollographql/apollo-link/pull/559) | ||
### 1.0.8 | ||
- update apollo link with zen-observable-ts [PR#515](https://github.com/apollographql/apollo-link/pull/515) | ||
### 1.0.7 | ||
- udate apollo link with zen-observable-ts [PR#515](https://github.com/apollographql/apollo-link/pull/515) | ||
- ApolloLink upgrade | ||
@@ -9,0 +15,0 @@ ### 1.0.6 |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link'], factory) : | ||
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.dedup = {}),global.apolloLink.core)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'apollo-link'], factory) : | ||
(factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.dedup = {}),global.apolloLink.core)); | ||
}(this, (function (exports,apolloLink) { 'use strict'; | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var DedupLink = (function (_super) { | ||
__extends(DedupLink, _super); | ||
function DedupLink() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.inFlightRequestObservables = new Map(); | ||
_this.subscribers = new Map(); | ||
return _this; | ||
} | ||
DedupLink.prototype.request = function (operation, forward) { | ||
var _this = this; | ||
if (operation.getContext().forceFetch) { | ||
return forward(operation); | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
/* | ||
* Expects context to contain the forceFetch field if no dedup | ||
*/ | ||
var DedupLink = /** @class */ (function (_super) { | ||
__extends(DedupLink, _super); | ||
function DedupLink() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.inFlightRequestObservables = new Map(); | ||
_this.subscribers = new Map(); | ||
return _this; | ||
} | ||
var key = operation.toKey(); | ||
var cleanup = function (key) { | ||
_this.inFlightRequestObservables.delete(key); | ||
var prev = _this.subscribers.get(key); | ||
return prev; | ||
}; | ||
if (!this.inFlightRequestObservables.get(key)) { | ||
var singleObserver_1 = forward(operation); | ||
var subscription_1; | ||
var sharedObserver = new apolloLink.Observable(function (observer) { | ||
DedupLink.prototype.request = function (operation, forward) { | ||
var _this = this; | ||
// sometimes we might not want to deduplicate a request, for example when we want to force fetch it. | ||
if (operation.getContext().forceFetch) { | ||
return forward(operation); | ||
} | ||
var key = operation.toKey(); | ||
var cleanup = function (key) { | ||
_this.inFlightRequestObservables.delete(key); | ||
var prev = _this.subscribers.get(key); | ||
if (!prev) | ||
prev = { next: [], error: [], complete: [] }; | ||
_this.subscribers.set(key, { | ||
next: prev.next.concat([observer.next.bind(observer)]), | ||
error: prev.error.concat([observer.error.bind(observer)]), | ||
complete: prev.complete.concat([observer.complete.bind(observer)]), | ||
return prev; | ||
}; | ||
if (!this.inFlightRequestObservables.get(key)) { | ||
// this is a new request, i.e. we haven't deduplicated it yet | ||
// call the next link | ||
var singleObserver_1 = forward(operation); | ||
var subscription_1; | ||
var sharedObserver = new apolloLink.Observable(function (observer) { | ||
// this will still be called by each subscriber regardless of | ||
// deduplication status | ||
var prev = _this.subscribers.get(key); | ||
if (!prev) | ||
prev = { next: [], error: [], complete: [] }; | ||
_this.subscribers.set(key, { | ||
next: prev.next.concat([observer.next.bind(observer)]), | ||
error: prev.error.concat([observer.error.bind(observer)]), | ||
complete: prev.complete.concat([observer.complete.bind(observer)]), | ||
}); | ||
if (!subscription_1) { | ||
subscription_1 = singleObserver_1.subscribe({ | ||
next: function (result) { | ||
var prev = cleanup(key); | ||
_this.subscribers.delete(key); | ||
if (prev) { | ||
prev.next.forEach(function (next) { return next(result); }); | ||
prev.complete.forEach(function (complete) { return complete(); }); | ||
} | ||
}, | ||
error: function (error) { | ||
var prev = cleanup(key); | ||
_this.subscribers.delete(key); | ||
if (prev) | ||
prev.error.forEach(function (err) { return err(error); }); | ||
}, | ||
}); | ||
} | ||
return function () { | ||
if (subscription_1) | ||
subscription_1.unsubscribe(); | ||
_this.inFlightRequestObservables.delete(key); | ||
}; | ||
}); | ||
if (!subscription_1) { | ||
subscription_1 = singleObserver_1.subscribe({ | ||
next: function (result) { | ||
var prev = cleanup(key); | ||
_this.subscribers.delete(key); | ||
if (prev) { | ||
prev.next.forEach(function (next) { return next(result); }); | ||
prev.complete.forEach(function (complete) { return complete(); }); | ||
} | ||
}, | ||
error: function (error) { | ||
var prev = cleanup(key); | ||
_this.subscribers.delete(key); | ||
if (prev) | ||
prev.error.forEach(function (err) { return err(error); }); | ||
}, | ||
}); | ||
} | ||
return function () { | ||
if (subscription_1) | ||
subscription_1.unsubscribe(); | ||
_this.inFlightRequestObservables.delete(key); | ||
}; | ||
}); | ||
this.inFlightRequestObservables.set(key, sharedObserver); | ||
} | ||
return this.inFlightRequestObservables.get(key); | ||
}; | ||
return DedupLink; | ||
}(apolloLink.ApolloLink)); | ||
this.inFlightRequestObservables.set(key, sharedObserver); | ||
} | ||
// return shared Observable | ||
return this.inFlightRequestObservables.get(key); | ||
}; | ||
return DedupLink; | ||
}(apolloLink.ApolloLink)); | ||
exports.DedupLink = DedupLink; | ||
exports.DedupLink = DedupLink; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=bundle.umd.js.map |
@@ -12,3 +12,6 @@ var __extends = (this && this.__extends) || (function () { | ||
import { ApolloLink, Observable, } from 'apollo-link'; | ||
var DedupLink = (function (_super) { | ||
/* | ||
* Expects context to contain the forceFetch field if no dedup | ||
*/ | ||
var DedupLink = /** @class */ (function (_super) { | ||
__extends(DedupLink, _super); | ||
@@ -23,2 +26,3 @@ function DedupLink() { | ||
var _this = this; | ||
// sometimes we might not want to deduplicate a request, for example when we want to force fetch it. | ||
if (operation.getContext().forceFetch) { | ||
@@ -34,5 +38,9 @@ return forward(operation); | ||
if (!this.inFlightRequestObservables.get(key)) { | ||
// this is a new request, i.e. we haven't deduplicated it yet | ||
// call the next link | ||
var singleObserver_1 = forward(operation); | ||
var subscription_1; | ||
var sharedObserver = new Observable(function (observer) { | ||
// this will still be called by each subscriber regardless of | ||
// deduplication status | ||
var prev = _this.subscribers.get(key); | ||
@@ -72,2 +80,3 @@ if (!prev) | ||
} | ||
// return shared Observable | ||
return this.inFlightRequestObservables.get(key); | ||
@@ -74,0 +83,0 @@ }; |
{ | ||
"name": "apollo-link-dedup", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Deduplicates queries that are currently on the wire", | ||
@@ -41,21 +41,21 @@ "author": "Evans Hauser <evanshauser@gmail.com>", | ||
"dependencies": { | ||
"apollo-link": "^1.2.1" | ||
"apollo-link": "^1.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/graphql": "0.12.4", | ||
"@types/jest": "21.1.10", | ||
"browserify": "16.1.0", | ||
"graphql": "0.13.1", | ||
"graphql-tag": "2.7.3", | ||
"jest": "21.2.1", | ||
"@types/graphql": "0.12.6", | ||
"@types/jest": "22.2.2", | ||
"browserify": "16.1.1", | ||
"graphql": "0.13.2", | ||
"graphql-tag": "2.8.0", | ||
"jest": "22.4.3", | ||
"rimraf": "2.6.1", | ||
"rollup": "0.56.2", | ||
"rollup": "0.57.1", | ||
"ts-jest": "21.2.4", | ||
"tslint": "5.9.1", | ||
"typescript": "2.7.2", | ||
"uglify-js": "3.3.11" | ||
"uglify-js": "3.3.16" | ||
}, | ||
"jest": { | ||
"transform": { | ||
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
".(ts|tsx)": "ts-jest" | ||
}, | ||
@@ -62,0 +62,0 @@ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", |
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
51442
781
Updatedapollo-link@^1.2.2