source: trip-planner-front/node_modules/tapable/lib/HookMap.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5"use strict";
6
7const util = require("util");
8
9const defaultFactory = (key, hook) => hook;
10
11class HookMap {
12 constructor(factory, name = undefined) {
13 this._map = new Map();
14 this.name = name;
15 this._factory = factory;
16 this._interceptors = [];
17 }
18
19 get(key) {
20 return this._map.get(key);
21 }
22
23 for(key) {
24 const hook = this.get(key);
25 if (hook !== undefined) {
26 return hook;
27 }
28 let newHook = this._factory(key);
29 const interceptors = this._interceptors;
30 for (let i = 0; i < interceptors.length; i++) {
31 newHook = interceptors[i].factory(key, newHook);
32 }
33 this._map.set(key, newHook);
34 return newHook;
35 }
36
37 intercept(interceptor) {
38 this._interceptors.push(
39 Object.assign(
40 {
41 factory: defaultFactory
42 },
43 interceptor
44 )
45 );
46 }
47}
48
49HookMap.prototype.tap = util.deprecate(function(key, options, fn) {
50 return this.for(key).tap(options, fn);
51}, "HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead.");
52
53HookMap.prototype.tapAsync = util.deprecate(function(key, options, fn) {
54 return this.for(key).tapAsync(options, fn);
55}, "HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead.");
56
57HookMap.prototype.tapPromise = util.deprecate(function(key, options, fn) {
58 return this.for(key).tapPromise(options, fn);
59}, "HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead.");
60
61module.exports = HookMap;
Note: See TracBrowser for help on using the repository browser.