Skip to content

Commit 2f8b881

Browse files
committed
Time improvements
1 parent ad3f2ff commit 2f8b881

File tree

10 files changed

+207
-263
lines changed

10 files changed

+207
-263
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
/**
2+
* @extends {Record<string, any>}
3+
*/
14
export class Attributes {
25
static $nonscope: boolean;
36
/**
7+
* Creates an Attributes instance.
8+
*
9+
* There are two construction modes:
10+
*
11+
* 1. **Fresh instance** (no `attributesToCopy`):
12+
* - Used when compiling a DOM element for the first time.
13+
* - Initializes a new `$attr` map to track normalized → DOM attribute names.
14+
*
15+
* 2. **Clone instance** (`attributesToCopy` provided):
16+
* - Used when cloning attributes for directive linking / child scopes.
17+
* - Performs a shallow copy of all properties from the source Attributes object,
18+
* including `$attr`, normalized attribute values, and internal fields
19+
* (e.g. `$$observers`).
20+
* - `$attr` is intentionally **not reinitialized** in this case, because the
21+
* source object already contains the correct normalized → DOM attribute mapping.
22+
*
423
* @param {ng.AnimateService} $animate
524
* @param {ng.ExceptionHandlerService} $exceptionHandler
625
* @param {*} $sce
@@ -17,6 +36,10 @@ export class Attributes {
1736
_$animate: import("../../animations/interface.ts").AnimateService;
1837
_$exceptionHandler: import("../../services/exception/interface.ts").ExceptionHandler;
1938
_$sce: any;
39+
/**
40+
* A map of DOM element attribute names to the normalized name. This is needed
41+
* to do reverse lookup from normalized name back to actual name.
42+
*/
2043
$attr: {};
2144
/** @type {import("../../shared/noderef.js").NodeRef} */
2245
$nodeRef: import("../../shared/noderef.js").NodeRef;
@@ -71,20 +94,21 @@ export class Attributes {
7194
attrName?: string | undefined,
7295
): void;
7396
/**
97+
* @template T
7498
* Observes an interpolated attribute.
7599
*
76100
* The observer function will be invoked once during the next `$digest` following
77101
* compilation. The observer is then invoked whenever the interpolated value
78102
* changes.
79103
*
80104
* @param {string} key Normalized key. (ie ngAttribute) .
81-
* @param {any} fn Function that will be called whenever
105+
* @param {(value?: T) => any} fn Function that will be called whenever
82106
the interpolated value of the attribute changes.
83107
* See the {@link guide/interpolation#how-text-and-attribute-bindings-work Interpolation
84108
* guide} for more info.
85-
* @returns {function()} Returns a deregistration function for this observer.
109+
* @returns {Function} Returns a deregistration function for this observer.
86110
*/
87-
$observe(key: string, fn: any): () => any;
111+
$observe<T>(key: string, fn: (value?: T) => any): Function;
88112
$$observers: any;
89113
setSpecialAttr(element: any, attrName: any, value: any): void;
90114
/**

@types/core/scope/interface.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,29 @@ export interface Listener {
1010
watchProp?: string;
1111
foreignListener?: ProxyConstructor;
1212
}
13+
export interface ScopeEvent {
14+
/**
15+
* the scope on which the event was $emit-ed or $broadcast-ed.
16+
*/
17+
targetScope: ng.Scope;
18+
/**
19+
* the scope that is currently handling the event. Once the event propagates through the scope hierarchy, this property is set to null.
20+
*/
21+
currentScope: ng.Scope;
22+
/**
23+
* name of the event.
24+
*/
25+
name: string;
26+
/**
27+
* calling stopPropagation function will cancel further event propagation (available only for events that were $emit-ed).
28+
*/
29+
stopPropagation?(): void;
30+
/**
31+
* calling preventDefault sets defaultPrevented flag to true.
32+
*/
33+
preventDefault(): void;
34+
/**
35+
* true if preventDefault was called.
36+
*/
37+
defaultPrevented: boolean;
38+
}

@types/namespace.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Scope as TScope } from "./core/scope/scope.js";
55
import {
66
ListenerFn as TListenerFn,
77
Listener as TListener,
8+
ScopeEvent as TScopeEvent,
89
} from "./core/scope/interface.ts";
910
import { NgModule as TNgModule } from "./core/di/ng-module/ng-module.js";
1011
import { InjectorService as TInjectorService } from "./core/di/internal-injector.js";
@@ -107,6 +108,10 @@ import { StateObject as TStateObject } from "./router/state/state-object.js";
107108
import { StateRegistryProvider as TStateRegistryProvider } from "./router/state/state-registry.js";
108109
import { ViewScrollService as TViewScrollService } from "./router/scroll/interface.ts";
109110
import { HookRegistry } from "./router/transition/interface.ts";
111+
import {
112+
SCEService as TSCEService,
113+
SCEDelegateService as TSCEDelegateService,
114+
} from "./services/sce/interface.ts";
110115
declare global {
111116
interface Function {
112117
$inject?: readonly string[] | undefined;
@@ -166,6 +171,8 @@ declare global {
166171
type RouterService = TRouterProvider;
167172
type StateService = TStateProvider;
168173
type StateRegistryService = TStateRegistryProvider;
174+
type SCEService = TSCEService;
175+
type SCEDelegateService = TSCEDelegateService;
169176
type SseService = TSseService;
170177
type SseConfig = TSseConfig;
171178
type TransitionService = TransitionProvider & HookRegistry;
@@ -206,5 +213,6 @@ declare global {
206213
type AnchorScrollFunction = TAnchorScrollFunction;
207214
type AnchorScrollObject = TAnchorScrollObject;
208215
type InjectionTokens = typeof PublicInjectionTokens;
216+
type ScopeEvent = TScopeEvent;
209217
}
210218
}

@types/services/sce/interface.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export interface SCEService {
2+
getTrusted(type: string, mayBeTrusted: any): any;
3+
getTrustedCss(value: any): any;
4+
getTrustedHtml(value: any): any;
5+
getTrustedJs(value: any): any;
6+
getTrustedResourceUrl(value: any): any;
7+
getTrustedUrl(value: any): any;
8+
parse(type: string, expression: string): (context: any, locals: any) => any;
9+
parseAsCss(expression: string): (context: any, locals: any) => any;
10+
parseAsHtml(expression: string): (context: any, locals: any) => any;
11+
parseAsJs(expression: string): (context: any, locals: any) => any;
12+
parseAsResourceUrl(expression: string): (context: any, locals: any) => any;
13+
parseAsUrl(expression: string): (context: any, locals: any) => any;
14+
trustAs(type: string, value: any): any;
15+
trustAsHtml(value: any): any;
16+
trustAsJs(value: any): any;
17+
trustAsResourceUrl(value: any): any;
18+
trustAsUrl(value: any): any;
19+
isEnabled(): boolean;
20+
}
21+
export interface SCEDelegateService {
22+
getTrusted(type: string, mayBeTrusted: any): any;
23+
trustAs(type: string, value: any): any;
24+
valueOf(value: any): any;
25+
}

0 commit comments

Comments
 (0)