[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const createHash = require("./util/createHash");
|
---|
| 9 |
|
---|
| 10 | /** @typedef {import("./Dependency")} Dependency */
|
---|
| 11 | /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
|
---|
| 12 | /** @typedef {new (...args: any[]) => Dependency} DependencyConstructor */
|
---|
| 13 |
|
---|
| 14 | class DependencyTemplates {
|
---|
| 15 | constructor() {
|
---|
| 16 | /** @type {Map<Function, DependencyTemplate>} */
|
---|
| 17 | this._map = new Map();
|
---|
| 18 | /** @type {string} */
|
---|
| 19 | this._hash = "31d6cfe0d16ae931b73c59d7e0c089c0";
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * @param {DependencyConstructor} dependency Constructor of Dependency
|
---|
| 24 | * @returns {DependencyTemplate} template for this dependency
|
---|
| 25 | */
|
---|
| 26 | get(dependency) {
|
---|
| 27 | return this._map.get(dependency);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * @param {DependencyConstructor} dependency Constructor of Dependency
|
---|
| 32 | * @param {DependencyTemplate} dependencyTemplate template for this dependency
|
---|
| 33 | * @returns {void}
|
---|
| 34 | */
|
---|
| 35 | set(dependency, dependencyTemplate) {
|
---|
| 36 | this._map.set(dependency, dependencyTemplate);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * @param {string} part additional hash contributor
|
---|
| 41 | * @returns {void}
|
---|
| 42 | */
|
---|
| 43 | updateHash(part) {
|
---|
| 44 | const hash = createHash("md4");
|
---|
| 45 | hash.update(this._hash);
|
---|
| 46 | hash.update(part);
|
---|
| 47 | this._hash = /** @type {string} */ (hash.digest("hex"));
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | getHash() {
|
---|
| 51 | return this._hash;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | clone() {
|
---|
| 55 | const newInstance = new DependencyTemplates();
|
---|
| 56 | newInstance._map = new Map(this._map);
|
---|
| 57 | newInstance._hash = this._hash;
|
---|
| 58 | return newInstance;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | module.exports = DependencyTemplates;
|
---|