Skip to content

Commit 64ec8a0

Browse files
author
Anatoly Ostrovsky
committed
Optimize attributes
1 parent f6675af commit 64ec8a0

File tree

5 files changed

+19
-37
lines changed

5 files changed

+19
-37
lines changed

@types/core/compile/attributes.d.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
export class Attributes {
22
static $nonscope: boolean;
33
/**
4-
* @param {ng.RootScopeService} $rootScope
54
* @param {ng.AnimateService} $animate
65
* @param {ng.ExceptionHandlerService} $exceptionHandler
76
* @param {*} $sce
87
* @param {import("../../shared/noderef.js").NodeRef} [nodeRef]
98
* @param {Object} [attributesToCopy]
109
*/
1110
constructor(
12-
$rootScope: ng.RootScopeService,
1311
$animate: ng.AnimateService,
1412
$exceptionHandler: ng.ExceptionHandlerService,
1513
$sce: any,
1614
nodeRef?: import("../../shared/noderef.js").NodeRef,
1715
attributesToCopy?: any,
1816
);
19-
$rootScope: ng.RootScopeService;
20-
$animate: import("../../interface.ts").AnimateService;
21-
$exceptionHandler: import("../../interface.ts").ExceptionHandler;
22-
$sce: any;
17+
_$animate: import("../../interface.ts").AnimateService;
18+
_$exceptionHandler: import("../../interface.ts").ExceptionHandler;
19+
_$sce: any;
2320
$attr: {};
2421
/** @type {import("../../shared/noderef.js").NodeRef} */
2522
$nodeRef: import("../../shared/noderef.js").NodeRef;

@types/core/compile/compile.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class CompileProvider {
113113
*
114114
* @param {string} elementName The element name or '*' to match any element.
115115
* @param {string} propertyName The DOM property name.
116-
* @param {string} ctx The {@link $sce} security context in which this value is safe for use, e.g. `$sce.URL`
116+
* @param {string} ctx The {@link _$sce} security context in which this value is safe for use, e.g. `$sce.URL`
117117
* @returns {object} `this` for chaining
118118
*/
119119
addPropertySecurityContext: (

src/core/compile/attributes.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,16 @@ export class Attributes {
2222
static $nonscope = true;
2323

2424
/**
25-
* @param {ng.RootScopeService} $rootScope
2625
* @param {ng.AnimateService} $animate
2726
* @param {ng.ExceptionHandlerService} $exceptionHandler
2827
* @param {*} $sce
2928
* @param {import("../../shared/noderef.js").NodeRef} [nodeRef]
3029
* @param {Object} [attributesToCopy]
3130
*/
32-
constructor(
33-
$rootScope,
34-
$animate,
35-
$exceptionHandler,
36-
$sce,
37-
nodeRef,
38-
attributesToCopy,
39-
) {
40-
this.$rootScope = $rootScope;
41-
this.$animate = $animate;
42-
this.$exceptionHandler = $exceptionHandler;
43-
this.$sce = $sce;
31+
constructor($animate, $exceptionHandler, $sce, nodeRef, attributesToCopy) {
32+
this._$animate = $animate;
33+
this._$exceptionHandler = $exceptionHandler;
34+
this._$sce = $sce;
4435

4536
if (attributesToCopy) {
4637
const keys = Object.keys(attributesToCopy);
@@ -84,7 +75,7 @@ export class Attributes {
8475
$addClass(classVal) {
8576
if (classVal && classVal.length > 0) {
8677
if (hasAnimate(this.$$element)) {
87-
this.$animate.addClass(
78+
this._$animate.addClass(
8879
/** @type {Element} */ (this.$$element),
8980
classVal,
9081
);
@@ -103,7 +94,7 @@ export class Attributes {
10394
$removeClass(classVal) {
10495
if (classVal && classVal.length > 0) {
10596
if (hasAnimate(this.$$element)) {
106-
this.$animate.removeClass(
97+
this._$animate.removeClass(
10798
/** @type {Element} */ (this.$$element),
10899
classVal,
109100
);
@@ -125,7 +116,7 @@ export class Attributes {
125116

126117
if (toAdd && toAdd.length) {
127118
if (hasAnimate(this.$$element)) {
128-
this.$animate.addClass(/** @type {Element }*/ (this.$$element), toAdd);
119+
this._$animate.addClass(/** @type {Element }*/ (this.$$element), toAdd);
129120
} else {
130121
this.$nodeRef.element.classList.add(...toAdd.trim().split(/\s+/));
131122
}
@@ -134,7 +125,7 @@ export class Attributes {
134125

135126
if (toRemove && toRemove.length) {
136127
if (hasAnimate(this.$$element)) {
137-
this.$animate.removeClass(
128+
this._$animate.removeClass(
138129
/** @type {Element }*/ (this.$$element),
139130
toRemove,
140131
);
@@ -228,7 +219,7 @@ export class Attributes {
228219
try {
229220
fn(value);
230221
} catch (err) {
231-
this.$exceptionHandler(err);
222+
this._$exceptionHandler(err);
232223
}
233224
});
234225
}
@@ -327,7 +318,7 @@ export class Attributes {
327318
const innerIdx = i * 2;
328319

329320
// sanitize the uri
330-
result += this.$sce.getTrustedMediaUrl(trim(rawUris[innerIdx]));
321+
result += this._$sce.getTrustedMediaUrl(trim(rawUris[innerIdx]));
331322
// add the descriptor
332323
result += ` ${trim(rawUris[innerIdx + 1])}`;
333324
}
@@ -336,7 +327,7 @@ export class Attributes {
336327
const lastTuple = trim(rawUris[i * 2]).split(/\s/);
337328

338329
// sanitize the last uri
339-
result += this.$sce.getTrustedMediaUrl(trim(lastTuple[0]));
330+
result += this._$sce.getTrustedMediaUrl(trim(lastTuple[0]));
340331

341332
// and add the last descriptor if any
342333
if (lastTuple.length === 2) {

src/core/compile/compile.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export class CompileProvider {
483483
*
484484
* @param {string} elementName The element name or '*' to match any element.
485485
* @param {string} propertyName The DOM property name.
486-
* @param {string} ctx The {@link $sce} security context in which this value is safe for use, e.g. `$sce.URL`
486+
* @param {string} ctx The {@link _$sce} security context in which this value is safe for use, e.g. `$sce.URL`
487487
* @returns {object} `this` for chaining
488488
*/
489489
this.addPropertySecurityContext = function (
@@ -814,12 +814,7 @@ export class CompileProvider {
814814
let linkFnFound = false;
815815

816816
for (let i = 0; i < nodeRefList.size; i++) {
817-
const attrs = new Attributes(
818-
$rootScope,
819-
$animate,
820-
$exceptionHandler,
821-
$sce,
822-
);
817+
const attrs = new Attributes($animate, $exceptionHandler, $sce);
823818

824819
const directives = collectDirectives(
825820
/** @type Element */ (nodeRefList.getIndex(i)),
@@ -1351,7 +1346,6 @@ export class CompileProvider {
13511346
} else {
13521347
$element = new NodeRef(linkNode);
13531348
attrs = new Attributes(
1354-
$rootScope,
13551349
$animate,
13561350
$exceptionHandler,
13571351
$sce,
@@ -2347,7 +2341,7 @@ export class CompileProvider {
23472341

23482342
// reapply the old attributes to the new element
23492343
entries(dst).forEach(([key, value]) => {
2350-
if (key.charAt(0) !== "$") {
2344+
if (key[0] !== "$" && key[0] !== "_") {
23512345
if (src[key] && src[key] !== value) {
23522346
if (value.length) {
23532347
value += (key === "style" ? ";" : " ") + src[key];

src/services/pubsub/pubsub.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("PubSub", function () {
3131
});
3232

3333
it("should provide injecables", function () {
34-
expect(pubsub.$exceptionHandler).not.toBeNull();
34+
expect(pubsub._$exceptionHandler).not.toBeNull();
3535
});
3636

3737
it("should dispose of the PubSub instance", function () {

0 commit comments

Comments
 (0)