1 | 'use strict';
|
2 |
|
3 | var utils = require('./../utils');
|
4 |
|
5 | function InterceptorManager() {
|
6 | this.handlers = [];
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
|
18 | this.handlers.push({
|
19 | fulfilled: fulfilled,
|
20 | rejected: rejected,
|
21 | synchronous: options ? options.synchronous : false,
|
22 | runWhen: options ? options.runWhen : null
|
23 | });
|
24 | return this.handlers.length - 1;
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | InterceptorManager.prototype.eject = function eject(id) {
|
33 | if (this.handlers[id]) {
|
34 | this.handlers[id] = null;
|
35 | }
|
36 | };
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | InterceptorManager.prototype.forEach = function forEach(fn) {
|
47 | utils.forEach(this.handlers, function forEachHandler(h) {
|
48 | if (h !== null) {
|
49 | fn(h);
|
50 | }
|
51 | });
|
52 | };
|
53 |
|
54 | module.exports = InterceptorManager;
|