Skip to content

Commit 23e1e36

Browse files
author
Anatoly Ostrovsky
committed
Performance optimizations and type improvements
1 parent 045951d commit 23e1e36

File tree

19 files changed

+100
-134
lines changed

19 files changed

+100
-134
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ types:
3333
@npx -p typescript tsc --project tsconfig.types.json
3434
$(MAKE) pretty
3535

36-
3736
TYPEDOC_DIR = docs/static/typedoc
3837
doc:
3938
@rm -rf $(TYPEDOC_DIR)
@@ -42,7 +41,9 @@ doc:
4241
@mv typedoc $(TYPEDOC_DIR)
4342

4443
serve:
45-
@npm run serve
44+
@vite --config utils/vite.config.js & \
45+
node --watch ./utils/express.js & \
46+
wait
4647

4748
prepare-release: test check types doc pretty build
4849

index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
}
3333

3434
increase() {
35-
console.log(this);
3635
this.counter++;
3736
}
3837

legacy.d.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
declare namespace legacy {
2-
// not directly implemented, but ensures that constructed class implements $get
3-
4-
///////////////////////////////////////////////////////////////////////////
5-
// Module
6-
// see http://docs.angularjs.org/api/angular.Module
7-
///////////////////////////////////////////////////////////////////////////
82
interface IModule {
93
/**
104
* Use this method to register a component.
@@ -40,21 +34,6 @@ declare namespace legacy {
4034
*/
4135
constant<T>(name: string, value: T): IModule;
4236
constant(object: Object): IModule;
43-
/**
44-
* The $controller service is used by Angular to create new controllers.
45-
*
46-
* This provider allows controller registration via the register method.
47-
*
48-
* @param name Controller name, or an object map of controllers where the keys are the names and the values are the constructors.
49-
* @param controllerConstructor Controller constructor fn (optionally decorated with DI annotations in the array notation).
50-
*/
51-
controller(
52-
name: string,
53-
controllerConstructor: Injectable<IControllerConstructor>,
54-
): IModule;
55-
controller(object: {
56-
[name: string]: Injectable<IControllerConstructor>;
57-
}): IModule;
5837
/**
5938
* Register a new directive with the compiler.
6039
*

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
"node": ">=24.0.0"
2727
},
2828
"scripts": {
29-
"serve": "npm-run-all --parallel dev express",
30-
"dev": "vite",
31-
"express": "node --watch ./utils/express.js",
32-
"build": "vite build",
3329
"playwright": "./node_modules/.bin/playwright test",
3430
"prepare": "husky"
3531
},
@@ -50,7 +46,6 @@
5046
"globals": "^16.2.0",
5147
"husky": "^9.1.7",
5248
"jasmine-core": "latest",
53-
"npm-run-all": "latest",
5449
"playwright": "latest",
5550
"postcss": "^8.5.6",
5651
"prettier": "latest",

src/animations/animate-swap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function ngAnimateSwapDirective($animate) {
1313
link(scope, $element, attrs, _ctrl, $transclude) {
1414
let previousElement;
1515
let previousScope;
16-
scope.$watch(attrs.ngAnimateSwap || attrs.for, (value) => {
16+
scope.$watch(attrs.ngAnimateSwap || attrs.for, function (value) {
1717
if (previousElement) {
1818
$animate.leave(previousElement);
1919
}
@@ -22,7 +22,7 @@ export function ngAnimateSwapDirective($animate) {
2222
previousScope = null;
2323
}
2424
if (value) {
25-
$transclude((clone, childScope) => {
25+
$transclude(function (clone, childScope) {
2626
previousElement = clone;
2727
previousScope = childScope;
2828
$animate.enter(clone, null, $element);

src/core/di/di.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { assertArgFn, minErr } from "../../shared/utils.js";
2-
import { INJECTOR_LITERAL } from "./ng-module/ng-module.js";
2+
import { $injectTokens } from "../../injection-tokens.js";
33

44
/**
55
* Shared utility functions
66
*/
77

8-
const $injectorMinErr = minErr(INJECTOR_LITERAL);
8+
const $injectorMinErr = minErr($injectTokens.$injector);
99
const ARROW_ARG = /^([^(]+?)=>/;
1010
const FN_ARGS = /^[^(]*\(\s*([^)]*)\)/m;
1111
const FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;

src/core/di/injector.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import {
99
isUndefined,
1010
minErr,
1111
} from "../../shared/utils.js";
12-
import { INJECTOR_LITERAL } from "./ng-module/ng-module.js";
1312
import { InjectorService, ProviderInjector } from "./internal-injector.js";
1413
import { createPersistentProxy } from "../../services/storage/storage.js";
1514
import { $injectTokens } from "../../injection-tokens";
1615

17-
const $injectorMinErr = minErr(INJECTOR_LITERAL);
16+
const $injectorMinErr = minErr($injectTokens.$injector);
1817
const providerSuffix = "Provider";
1918

2019
/**
@@ -55,7 +54,7 @@ export function createInjector(modulesToLoad, strictDi = false) {
5554

5655
let instanceInjector = protoInstanceInjector;
5756
const runBlocks = loadModules(modulesToLoad);
58-
instanceInjector = protoInstanceInjector.get(INJECTOR_LITERAL);
57+
instanceInjector = protoInstanceInjector.get($injectTokens.$injector);
5958

6059
runBlocks.forEach((fn) => fn && instanceInjector.invoke(fn));
6160

@@ -125,7 +124,7 @@ export function createInjector(modulesToLoad, strictDi = false) {
125124
*/
126125
function service(name, constructor) {
127126
return factory(name, [
128-
INJECTOR_LITERAL,
127+
$injectTokens.$injector,
129128
($injector) => $injector.instantiate(constructor),
130129
]);
131130
}

src/core/di/internal-injector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { hasOwn, minErr } from "../../shared/utils.js";
22
import { annotate, isClass } from "./di.js";
3-
import { INJECTOR_LITERAL } from "./ng-module/ng-module.js";
3+
import { $injectTokens } from "../../injection-tokens.js";
44

5-
const $injectorMinErr = minErr(INJECTOR_LITERAL);
5+
const $injectorMinErr = minErr($injectTokens.$injector);
66

77
const providerSuffix = "Provider";
88
const INSTANTIATING = true;

src/core/di/ng-module/ng-module.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
instantiateWasm,
88
} from "../../../shared/utils.js";
99

10-
/** @private */
11-
export const INJECTOR_LITERAL = "$injector";
1210
/** @private */
1311
export const COMPILE_LITERAL = "$compileProvider";
1412
/** @private */
@@ -23,10 +21,6 @@ export const CONTROLLER_LITERAL = "$controllerProvider";
2321
* controllers, directives, filters, etc. They provide recipes for the injector
2422
* to do the actual instantiation. A module itself has no behaviour but only state.
2523
* A such, it acts as a data structure between the Angular instance and the injector service.
26-
*
27-
* Since this is an internal structure that is exposed only via the Angular instance,
28-
* it contains no validation of the items it receives. It is up to the instantiator on
29-
* modules to do the actual validation.
3024
*/
3125
export class NgModule {
3226
/**
@@ -67,8 +61,6 @@ export class NgModule {
6761

6862
this.services = [];
6963

70-
this.wasmModules = [];
71-
7264
this.restDefinitions = [];
7365
}
7466

@@ -98,7 +90,7 @@ export class NgModule {
9890
* @returns {NgModule}
9991
*/
10092
config(configFn) {
101-
this.configBlocks.push([INJECTOR_LITERAL, "invoke", [configFn]]);
93+
this.configBlocks.push([$t.$injector, "invoke", [configFn]]);
10294
return this;
10395
}
10496

@@ -225,8 +217,11 @@ export class NgModule {
225217
}
226218

227219
/**
228-
* @param {string} name
229-
* @param {ng.Injectable<any>} ctlFn
220+
* The $controller service is used by Angular to create new controllers.
221+
* This provider allows controller registration via the register method.
222+
*
223+
* @param {string} name Controller name
224+
* @param {ng.Injectable<ng.ControllerConstructor>} ctlFn Controller constructor fn (optionally decorated with DI annotations in the array notation)
230225
* @returns {NgModule}
231226
*/
232227
controller(name, ctlFn) {

src/core/di/ng-module/ng-module.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
INJECTOR_LITERAL,
32
NgModule,
43
COMPILE_LITERAL,
54
ANIMATION_LITERAL,
@@ -82,12 +81,12 @@ describe("NgModule", () => {
8281

8382
// then they are appended to config queue
8483
expect(ngModule.configBlocks[0]).toEqual([
85-
INJECTOR_LITERAL,
84+
$injectTokens.$injector,
8685
"invoke",
8786
[fn1],
8887
]);
8988
expect(ngModule.configBlocks[1]).toEqual([
90-
INJECTOR_LITERAL,
89+
$injectTokens.$injector,
9190
"invoke",
9291
[fn2],
9392
]);

0 commit comments

Comments
 (0)