Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 45bb4ed

Browse files
committed
refactor: prefix private props with underscore
1 parent 4ae2d3f commit 45bb4ed

3 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/injector.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ function constructResolvingMessage(resolving, token) {
4040
class Injector {
4141

4242
constructor(modules = [], parentInjector = null, providers = new Map(), scopes = []) {
43-
this.cache = new Map();
44-
this.providers = providers;
45-
this.parent = parentInjector;
46-
this.scopes = scopes;
43+
this._cache = new Map();
44+
this._providers = providers;
45+
this._parent = parentInjector;
46+
this._scopes = scopes;
4747

4848
this._loadModules(modules);
4949

@@ -54,20 +54,20 @@ class Injector {
5454
// Collect all registered providers that has given annotation.
5555
// Inclugind providers defined in parent injectors.
5656
_collectProvidersWithAnnotation(annotationClass, collectedProviders) {
57-
this.providers.forEach((provider, token) => {
57+
this._providers.forEach((provider, token) => {
5858
if (!collectedProviders.has(token) && hasAnnotation(provider.provider, annotationClass)) {
5959
collectedProviders.set(token, provider);
6060
}
6161
});
6262

63-
if (this.parent) {
64-
this.parent._collectProvidersWithAnnotation(annotationClass, collectedProviders);
63+
if (this._parent) {
64+
this._parent._collectProvidersWithAnnotation(annotationClass, collectedProviders);
6565
}
6666
}
6767

6868

6969
// Load modules/function/classes.
70-
// This mutates `this.providers`, but it is only called during the constructor.
70+
// This mutates `this._providers`, but it is only called during the constructor.
7171
_loadModules(modules) {
7272
for (var module of modules) {
7373
// A single provider (class or function).
@@ -82,26 +82,26 @@ class Injector {
8282

8383

8484
// Load a function or class.
85-
// This mutates `this.providers`, but it is only called during the constructor.
85+
// This mutates `this._providers`, but it is only called during the constructor.
8686
_loadFnOrClass(fnOrClass) {
8787
// TODO(vojta): should we expose provider.token?
8888
var annotations = readAnnotations(fnOrClass);
8989
var token = annotations.provide.token || fnOrClass;
9090
var provider = createProviderFromFnOrClass(fnOrClass, annotations);
9191

92-
this.providers.set(token, provider);
92+
this._providers.set(token, provider);
9393
}
9494

9595

9696
// Returns true if there is any provider registered for given token.
9797
// Inclugind parent injectors.
9898
_hasProviderFor(token) {
99-
if (this.providers.has(token)) {
99+
if (this._providers.has(token)) {
100100
return true;
101101
}
102102

103-
if (this.parent) {
104-
return this.parent._hasProviderFor(token);
103+
if (this._parent) {
104+
return this._parent._hasProviderFor(token);
105105
}
106106

107107
return false;
@@ -110,21 +110,21 @@ class Injector {
110110
// Find the correct injector where the default provider should be instantiated and cached.
111111
_instantiateDefaultProvider(provider, token, resolving, wantPromise, wantLazy) {
112112
// In root injector, instantiate here.
113-
if (!this.parent) {
114-
this.providers.set(token, provider);
113+
if (!this._parent) {
114+
this._providers.set(token, provider);
115115
return this.get(token, resolving, wantPromise, wantLazy);
116116
}
117117

118118
// Check if this injector forces new instance of this provider.
119-
for (var ScopeClass of this.scopes) {
119+
for (var ScopeClass of this._scopes) {
120120
if (hasAnnotation(provider.provider, ScopeClass)) {
121-
this.providers.set(token, provider);
121+
this._providers.set(token, provider);
122122
return this.get(token, resolving, wantPromise, wantLazy);
123123
}
124124
}
125125

126126
// Otherwise ask parent injector.
127-
return this.parent._instantiateDefaultProvider(provider, token, resolving, wantPromise, wantLazy);
127+
return this._parent._instantiateDefaultProvider(provider, token, resolving, wantPromise, wantLazy);
128128
}
129129

130130

@@ -178,9 +178,9 @@ class Injector {
178178
}
179179

180180
// Check if there is a cached instance already.
181-
if (this.cache.has(token)) {
182-
instance = this.cache.get(token);
183-
provider = this.providers.get(token);
181+
if (this._cache.has(token)) {
182+
instance = this._cache.get(token);
183+
provider = this._providers.get(token);
184184

185185
if (provider.isPromise && !wantPromise) {
186186
resolvingMsg = constructResolvingMessage(resolving, token);
@@ -194,7 +194,7 @@ class Injector {
194194
return instance;
195195
}
196196

197-
provider = this.providers.get(token);
197+
provider = this._providers.get(token);
198198

199199
// No provider defined (overriden), use the default provider (token).
200200
if (!provider && isFunction(token) && !this._hasProviderFor(token)) {
@@ -203,12 +203,12 @@ class Injector {
203203
}
204204

205205
if (!provider) {
206-
if (!this.parent) {
206+
if (!this._parent) {
207207
resolvingMsg = constructResolvingMessage(resolving, token);
208208
throw new Error(`No provider for ${toString(token)}!${resolvingMsg}`);
209209
}
210210

211-
return this.parent.get(token, resolving, wantPromise, wantLazy);
211+
return this._parent.get(token, resolving, wantPromise, wantLazy);
212212
}
213213

214214
if (resolving.indexOf(token) !== -1) {
@@ -254,7 +254,7 @@ class Injector {
254254
}
255255

256256
if (!hasAnnotation(provider.provider, TransientScopeAnnotation)) {
257-
injector.cache.set(token, instance);
257+
injector._cache.set(token, instance);
258258
}
259259

260260
// TODO(vojta): if a provider returns a promise (but is not declared as @ProvidePromise),
@@ -276,7 +276,7 @@ class Injector {
276276
}
277277

278278
if (!hasAnnotation(provider.provider, TransientScopeAnnotation)) {
279-
this.cache.set(token, instance);
279+
this._cache.set(token, instance);
280280
}
281281

282282
if (!wantPromise && provider.isPromise) {

src/profiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function serializeProvider(provider, key, tokens) {
4848
function serializeInjector(injector, tokens, Injector) {
4949
var serializedInjector = {
5050
id: serializeToken(injector, tokens),
51-
parent_id: injector.parent ? serializeToken(injector.parent, tokens) : null,
51+
parent_id: injector._parent ? serializeToken(injector._parent, tokens) : null,
5252
providers: {}
5353
};
5454

@@ -60,7 +60,7 @@ function serializeInjector(injector, tokens, Injector) {
6060
dependencies: []
6161
};
6262

63-
injector.providers.forEach(function(provider, key) {
63+
injector._providers.forEach(function(provider, key) {
6464
var serializedProvider = serializeProvider(provider, key, tokens);
6565
serializedInjector.providers[serializedProvider.id] = serializedProvider;
6666
});

src/providers.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ class ClassProvider {
3333
this.isPromise = isPromise;
3434

3535
this.params = [];
36-
this.constructors = [];
36+
this._constructors = [];
3737

3838
this._flattenParams(clazz, params);
39-
this.constructors.unshift([clazz, 0, this.params.length - 1]);
39+
this._constructors.unshift([clazz, 0, this.params.length - 1]);
4040
}
4141

4242
// Normalize params for all the constructors (in the case of inheritance),
4343
// into a single flat array of DependencyDesriptors.
4444
// So that the injector does not have to worry about inheritance.
4545
//
46-
// This function mutates `this.params` and `this.constructors`,
46+
// This function mutates `this.params` and `this._constructors`,
4747
// but it is only called during the constructor.
4848
// TODO(vojta): remove the annotations argument?
4949
_flattenParams(constructor, params) {
@@ -59,7 +59,7 @@ class ClassProvider {
5959
}
6060

6161
constructorInfo = [SuperConstructor, this.params.length];
62-
this.constructors.push(constructorInfo);
62+
this._constructors.push(constructorInfo);
6363
this._flattenParams(SuperConstructor, readAnnotations(SuperConstructor).params);
6464
constructorInfo.push(this.params.length - 1);
6565
} else {
@@ -72,8 +72,8 @@ class ClassProvider {
7272
// We get arguments for all the constructors as a single flat array.
7373
// This method generates pre-bound "superConstructor" wrapper with correctly passing arguments.
7474
_createConstructor(currentConstructorIdx, context, allArguments) {
75-
var constructorInfo = this.constructors[currentConstructorIdx];
76-
var nextConstructorInfo = this.constructors[currentConstructorIdx + 1];
75+
var constructorInfo = this._constructors[currentConstructorIdx];
76+
var nextConstructorInfo = this._constructors[currentConstructorIdx + 1];
7777
var argsForCurrentConstructor;
7878

7979
if (nextConstructorInfo) {

0 commit comments

Comments
 (0)