2016-08-03 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-08-03 18:00:07 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
import {Injector, Metric, MultiMetric} from '../../index';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2017-12-17 18:10:54 -05:00
|
|
|
(function() {
|
2020-04-13 19:40:21 -04:00
|
|
|
function createMetric(ids: any[]) {
|
|
|
|
const m = Injector
|
|
|
|
.create([
|
|
|
|
ids.map(id => ({provide: id, useValue: new MockMetric(id)})),
|
|
|
|
MultiMetric.provideWith(ids)
|
|
|
|
])
|
|
|
|
.get<MultiMetric>(MultiMetric);
|
|
|
|
return Promise.resolve(m);
|
|
|
|
}
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
describe('multi metric', () => {
|
2021-05-23 16:16:02 -04:00
|
|
|
it('should merge descriptions', done => {
|
|
|
|
createMetric(['m1', 'm2']).then((m) => {
|
|
|
|
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2021-05-23 16:16:02 -04:00
|
|
|
it('should merge all beginMeasure calls', done => {
|
|
|
|
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
|
|
|
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-04-13 19:40:21 -04:00
|
|
|
|
|
|
|
[false, true].forEach((restartFlag) => {
|
2021-05-23 16:16:02 -04:00
|
|
|
it(`should merge all endMeasure calls for restart=${restartFlag}`, done => {
|
|
|
|
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
|
|
|
expect(values).toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
});
|
2020-04-13 19:40:21 -04:00
|
|
|
});
|
2017-12-16 17:42:55 -05:00
|
|
|
})();
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
class MockMetric extends Metric {
|
2020-04-13 19:40:21 -04:00
|
|
|
constructor(private _id: string) {
|
|
|
|
super();
|
|
|
|
}
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
beginMeasure(): Promise<string> {
|
|
|
|
return Promise.resolve(`${this._id}_beginMeasure`);
|
|
|
|
}
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
endMeasure(restart: boolean): Promise<{[key: string]: any}> {
|
2016-11-12 08:08:58 -05:00
|
|
|
const result: {[key: string]: any} = {};
|
2015-06-12 10:50:45 -04:00
|
|
|
result[this._id] = {'restart': restart};
|
2016-04-28 20:50:03 -04:00
|
|
|
return Promise.resolve(result);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
describe(): {[key: string]: string} {
|
2016-11-12 08:08:58 -05:00
|
|
|
const result: {[key: string]: string} = {};
|
2015-05-27 17:57:54 -04:00
|
|
|
result[this._id] = 'describe';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|