1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { stringify } from './facade/lang';
|
9 | import { resolveForwardRef } from './forward_ref';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | var ReflectiveKey = (function () {
|
27 | |
28 |
|
29 |
|
30 | function ReflectiveKey(token, id) {
|
31 | this.token = token;
|
32 | this.id = id;
|
33 | if (!token) {
|
34 | throw new Error('Token must be defined!');
|
35 | }
|
36 | }
|
37 | Object.defineProperty(ReflectiveKey.prototype, "displayName", {
|
38 | |
39 |
|
40 |
|
41 | get: function () {
|
42 | return stringify(this.token);
|
43 | },
|
44 | enumerable: false,
|
45 | configurable: true
|
46 | });
|
47 | |
48 |
|
49 |
|
50 | ReflectiveKey.get = function (token) {
|
51 |
|
52 | return _globalKeyRegistry.get(resolveForwardRef(token));
|
53 | };
|
54 | Object.defineProperty(ReflectiveKey, "numberOfKeys", {
|
55 | |
56 |
|
57 |
|
58 | get: function () {
|
59 |
|
60 | return _globalKeyRegistry.numberOfKeys;
|
61 | },
|
62 | enumerable: false,
|
63 | configurable: true
|
64 | });
|
65 | return ReflectiveKey;
|
66 | }());
|
67 | export { ReflectiveKey };
|
68 |
|
69 |
|
70 |
|
71 | var KeyRegistry = (function () {
|
72 | function KeyRegistry() {
|
73 | this._allKeys = new Map();
|
74 | }
|
75 | KeyRegistry.prototype.get = function (token) {
|
76 | if (token instanceof ReflectiveKey)
|
77 | return token;
|
78 | if (this._allKeys.has(token)) {
|
79 | return this._allKeys.get(token);
|
80 | }
|
81 | var newKey = new ReflectiveKey(token, ReflectiveKey.numberOfKeys);
|
82 | this._allKeys.set(token, newKey);
|
83 | return newKey;
|
84 | };
|
85 | Object.defineProperty(KeyRegistry.prototype, "numberOfKeys", {
|
86 | get: function () {
|
87 | return this._allKeys.size;
|
88 | },
|
89 | enumerable: false,
|
90 | configurable: true
|
91 | });
|
92 | return KeyRegistry;
|
93 | }());
|
94 | export { KeyRegistry };
|
95 | var _globalKeyRegistry = new KeyRegistry();
|
96 |
|
\ | No newline at end of file |