Skip to content

Commit 7c7d828

Browse files
author
Anatoly Ostrovsky
committed
Remove object registration from filterProvider
1 parent 1aa454e commit 7c7d828

File tree

12 files changed

+100
-268
lines changed

12 files changed

+100
-268
lines changed

@types/core/di/ng-module/ng-module.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ export const COMPILE_LITERAL: "$compileProvider";
33
/** @private */
44
export const ANIMATION_LITERAL: "$animateProvider";
55
/** @private */
6-
export const FILTER_LITERAL: "$filterProvider";
7-
/** @private */
86
export const CONTROLLER_LITERAL: "$controllerProvider";
97
/**
108
* Modules are collections of application configuration information for components:
@@ -111,10 +109,10 @@ export class NgModule {
111109
animation(name: string, animationFactory: ng.Injectable<any>): NgModule;
112110
/**
113111
* @param {string} name
114-
* @param {ng.Injectable<any>} filterFn
112+
* @param {ng.Injectable<ng.FilterFactory>} filterFn
115113
* @return {NgModule}
116114
*/
117-
filter(name: string, filterFn: ng.Injectable<any>): NgModule;
115+
filter(name: string, filterFn: ng.Injectable<ng.FilterFactory>): NgModule;
118116
/**
119117
* The $controller service is used by Angular to create new controllers.
120118
* This provider allows controller registration via the register method.

@types/core/filter/filter.d.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* $filterProvider - $filter - provider in module ng
3+
*
4+
* Filters are just functions which transform input to an output. However filters need to be Dependency Injected. To achieve this a filter definition consists of a factory function which is annotated with dependencies and is responsible for creating a filter function.
5+
* @extends {ng.ServiceProvider}
6+
*/
17
export class FilterProvider {
28
static $inject: string[];
39
/**
@@ -6,18 +12,14 @@ export class FilterProvider {
612
constructor($provide: ng.ProvideService);
713
$provide: import("../../interface.ts").Provider;
814
/**
9-
* @param {string|Record<string, ng.FilterFn>} name
10-
* @param {ng.FilterService} [factory]
11-
* @return {import('../../interface.ts').Provider}
15+
* Register a filter a config phase;
16+
* @param {string} name
17+
* @param {ng.Injectable<ng.FilterFactory>} factory
18+
* @return {ng.FilterProvider}
1219
*/
1320
register(
14-
name: string | Record<string, ng.FilterFn>,
15-
factory?: ng.FilterService,
16-
): import("../../interface.ts").Provider;
17-
$get: (
18-
| string
19-
| ((
20-
$injector: import("../../core/di/internal-injector.js").InjectorService,
21-
) => ng.FilterService)
22-
)[];
21+
name: string,
22+
factory: ng.Injectable<ng.FilterFactory>,
23+
): ng.FilterProvider;
24+
$get: (string | (($injector: ng.InjectorService) => ng.FilterFactory))[];
2325
}

@types/directive/input/input.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export function rangeInputType(
4545
ctrl: any,
4646
): void;
4747
/**
48-
* @param {ng.FilterService} $filter
48+
* @param {ng.FilterFactory} $filter
4949
* @param {ng.ParseService} $parse
5050
* @returns {ng.Directive}
5151
*/
5252
export function inputDirective(
53-
$filter: ng.FilterService,
53+
$filter: ng.FilterFactory,
5454
$parse: ng.ParseService,
5555
): ng.Directive;
5656
export namespace inputDirective {

@types/namespace.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
FilterFactory as TFilterFactory,
2323
FilterFn as TFilterFn,
2424
} from "./filters/interface.ts";
25+
import { FilterProvider as TFilterProvider } from "./core/filter/filter.js";
2526
import { InterpolateService as TInterpolateService } from "./core/interpolate/interface.ts";
2627
import { InterpolateProvider as TInterpolateProvider } from "./core/interpolate/interpolate.js";
2728
import {
@@ -99,7 +100,6 @@ declare global {
99100
type Scope = TScope;
100101
type NgModule = TNgModule;
101102
type PubSubProvider = TPubSubProvider;
102-
type FilterFn = TFilterFn;
103103
type CompositeLinkFn = TCompositeLinkFn;
104104
type PublicLinkFn = TPublicLinkFn;
105105
type NodeLinkFn = TNodeLinkFn;
@@ -112,13 +112,15 @@ declare global {
112112
type HttpParamSerializerProvider = THttpParamSerializerProvider;
113113
type SceProvider = TSceProvider;
114114
type SceDelegateProvider = TSceDelegateProvider;
115+
type FilterProvider = TFilterProvider;
115116
type AnchorScrollService = TAnchorScrollService;
116117
type AnimateService = TAnimateService;
117118
type CompileService = TCompileFn;
118119
type ControllerService = TControllerService;
119120
type CookieService = TCookieService;
120121
type ExceptionHandlerService = TExceptionHandler;
121-
type FilterService = TFilterFactory;
122+
type FilterFn = TFilterFn;
123+
type FilterFactory = TFilterFactory;
122124
type HttpParamSerializerSerService = THttpParamSerializer;
123125
type HttpService = THttpService;
124126
type InterpolateService = TInterpolateService;

legacy.d.ts

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -339,192 +339,6 @@ declare namespace legacy {
339339
defaultPrevented: boolean;
340340
}
341341

342-
/**
343-
* $filter - $filterProvider - service in module ng
344-
*
345-
* Filters are used for formatting data displayed to the user.
346-
*
347-
* see https://docs.angularjs.org/api/ng/service/$filter
348-
*/
349-
interface IFilterService {
350-
(name: "filter"): IFilterFilter;
351-
(name: "currency"): IFilterCurrency;
352-
(name: "number"): IFilterNumber;
353-
(name: "date"): IFilterDate;
354-
(name: "json"): IFilterJson;
355-
(name: "lowercase"): IFilterLowercase;
356-
(name: "uppercase"): IFilterUppercase;
357-
(name: "limitTo"): IFilterLimitTo;
358-
(name: "orderBy"): IFilterOrderBy;
359-
/**
360-
* Usage:
361-
* $filter(name);
362-
*
363-
* @param name Name of the filter function to retrieve
364-
*/
365-
<T>(name: string): T;
366-
}
367-
368-
interface IFilterFilter {
369-
<T>(
370-
array: T[],
371-
expression:
372-
| string
373-
| IFilterFilterPatternObject
374-
| IFilterFilterPredicateFunc<T>,
375-
comparator?: IFilterFilterComparatorFunc<T> | boolean,
376-
): T[];
377-
}
378-
379-
interface IFilterFilterPatternObject {
380-
[name: string]: any;
381-
}
382-
383-
interface IFilterFilterPredicateFunc<T> {
384-
(value: T, index: number, array: T[]): boolean;
385-
}
386-
387-
interface IFilterFilterComparatorFunc<T> {
388-
(actual: T, expected: T): boolean;
389-
}
390-
391-
interface IFilterOrderByItem {
392-
value: any;
393-
type: string;
394-
index: any;
395-
}
396-
397-
interface IFilterOrderByComparatorFunc {
398-
(left: IFilterOrderByItem, right: IFilterOrderByItem): -1 | 0 | 1;
399-
}
400-
401-
interface IFilterCurrency {
402-
/**
403-
* Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default symbol for current locale is used.
404-
* @param amount Input to filter.
405-
* @param symbol Currency symbol or identifier to be displayed.
406-
* @param fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale
407-
* @return Formatted number
408-
*/
409-
(amount: number, symbol?: string, fractionSize?: number): string;
410-
}
411-
412-
interface IFilterNumber {
413-
/**
414-
* Formats a number as text.
415-
* @param number Number to format.
416-
* @param fractionSize Number of decimal places to round the number to. If this is not provided then the fraction size is computed from the current locale's number formatting pattern. In the case of the default locale, it will be 3.
417-
* @return Number rounded to decimalPlaces and places a “,” after each third digit.
418-
*/
419-
(value: number | string, fractionSize?: number | string): string;
420-
}
421-
422-
interface IFilterDate {
423-
/**
424-
* Formats date to a string based on the requested format.
425-
*
426-
* @param date Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
427-
* @param format Formatting rules (see Description). If not specified, mediumDate is used.
428-
* @param timezone Timezone to be used for formatting. It understands UTC/GMT and the continental US time zone abbreviations, but for general use, use a time zone offset, for example, '+0430' (4 hours, 30 minutes east of the Greenwich meridian) If not specified, the timezone of the browser will be used.
429-
* @return Formatted string or the input if input is not recognized as date/millis.
430-
*/
431-
(date: Date | number | string, format?: string, timezone?: string): string;
432-
}
433-
434-
interface IFilterJson {
435-
/**
436-
* Allows you to convert a JavaScript object into JSON string.
437-
* @param object Any JavaScript object (including arrays and primitive types) to filter.
438-
* @param spacing The number of spaces to use per indentation, defaults to 2.
439-
* @return JSON string.
440-
*/
441-
(object: any, spacing?: number): string;
442-
}
443-
444-
interface IFilterLowercase {
445-
/**
446-
* Converts string to lowercase.
447-
*/
448-
(value: string): string;
449-
}
450-
451-
interface IFilterUppercase {
452-
/**
453-
* Converts string to uppercase.
454-
*/
455-
(value: string): string;
456-
}
457-
458-
interface IFilterLimitTo {
459-
/**
460-
* Creates a new array containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array, string or number, as specified by the value and sign (positive or negative) of limit.
461-
* @param input Source array to be limited.
462-
* @param limit The length of the returned array. If the limit number is positive, limit number of items from the beginning of the source array/string are copied. If the number is negative, limit number of items from the end of the source array are copied. The limit will be trimmed if it exceeds array.length. If limit is undefined, the input will be returned unchanged.
463-
* @param begin Index at which to begin limitation. As a negative index, begin indicates an offset from the end of input. Defaults to 0.
464-
* @return A new sub-array of length limit or less if input array had less than limit elements.
465-
*/
466-
<T>(input: T[], limit: string | number, begin?: string | number): T[];
467-
/**
468-
* Creates a new string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source string or number, as specified by the value and sign (positive or negative) of limit. If a number is used as input, it is converted to a string.
469-
* @param input Source string or number to be limited.
470-
* @param limit The length of the returned string. If the limit number is positive, limit number of items from the beginning of the source string are copied. If the number is negative, limit number of items from the end of the source string are copied. The limit will be trimmed if it exceeds input.length. If limit is undefined, the input will be returned unchanged.
471-
* @param begin Index at which to begin limitation. As a negative index, begin indicates an offset from the end of input. Defaults to 0.
472-
* @return A new substring of length limit or less if input had less than limit elements.
473-
*/
474-
(
475-
input: string | number,
476-
limit: string | number,
477-
begin?: string | number,
478-
): string;
479-
}
480-
481-
interface IFilterOrderBy {
482-
/**
483-
* Orders a specified array by the expression predicate. It is ordered alphabetically for strings and numerically for numbers. Note: if you notice numbers are not being sorted as expected, make sure they are actually being saved as numbers and not strings.
484-
* @param array The array to sort.
485-
* @param expression A predicate to be used by the comparator to determine the order of elements.
486-
* @param reverse Reverse the order of the array.
487-
* @param comparator Function used to determine the relative order of value pairs.
488-
* @return An array containing the items from the specified collection, ordered by a comparator function based on the values computed using the expression predicate.
489-
*/
490-
<T>(
491-
array: T[],
492-
expression:
493-
| string
494-
| ((value: T) => any)
495-
| Array<((value: T) => any) | string>,
496-
reverse?: boolean,
497-
comparator?: IFilterOrderByComparatorFunc,
498-
): T[];
499-
}
500-
501-
/**
502-
* $filterProvider - $filter - provider in module ng
503-
*
504-
* Filters are just functions which transform input to an output. However filters need to be Dependency Injected. To achieve this a filter definition consists of a factory function which is annotated with dependencies and is responsible for creating a filter function.
505-
*
506-
* see https://docs.angularjs.org/api/ng/provider/$filterProvider
507-
*/
508-
interface IFilterProvider extends IServiceProvider {
509-
/**
510-
* register(name);
511-
*
512-
* @param name Name of the filter function, or an object map of filters where the keys are the filter names and the values are the filter factories. Note: Filter names must be valid angular Expressions identifiers, such as uppercase or orderBy. Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace your filters, then you can use capitalization (myappSubsectionFilterx) or underscores (myapp_subsection_filterx).
513-
*/
514-
register(name: string | {}): IServiceProvider;
515-
}
516-
517-
interface ILogProvider extends IServiceProvider {
518-
debugEnabled(): boolean;
519-
debugEnabled(enabled: boolean): ILogProvider;
520-
}
521-
522-
// We define this as separate interface so we can reopen it later for
523-
// the ngMock module.
524-
interface ILogCall {
525-
(...args: any[]): void;
526-
}
527-
528342
///////////////////////////////////////////////////////////////////////////
529343
// ParseService
530344
// see http://docs.angularjs.org/api/ng/service/$parse

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export const COMPILE_LITERAL = "$compileProvider";
1212
/** @private */
1313
export const ANIMATION_LITERAL = "$animateProvider";
1414
/** @private */
15-
export const FILTER_LITERAL = "$filterProvider";
16-
/** @private */
1715
export const CONTROLLER_LITERAL = "$controllerProvider";
1816

1917
/**
@@ -205,14 +203,14 @@ export class NgModule {
205203

206204
/**
207205
* @param {string} name
208-
* @param {ng.Injectable<any>} filterFn
206+
* @param {ng.Injectable<ng.FilterFactory>} filterFn
209207
* @return {NgModule}
210208
*/
211209
filter(name, filterFn) {
212-
if (filterFn && isFunction(filterFn)) {
210+
if (isFunction(filterFn)) {
213211
filterFn["$$moduleName"] = name;
214212
}
215-
this.invokeQueue.push([FILTER_LITERAL, "register", [name, filterFn]]);
213+
this.invokeQueue.push([$t.$filterProvider, "register", [name, filterFn]]);
216214
return this;
217215
}
218216

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
NgModule,
33
COMPILE_LITERAL,
44
ANIMATION_LITERAL,
5-
FILTER_LITERAL,
65
CONTROLLER_LITERAL,
76
} from "./ng-module.js";
87
import { $injectTokens } from "../../../injection-tokens.js";
@@ -228,12 +227,12 @@ describe("NgModule", () => {
228227
it("can store filters", () => {
229228
ngModule.filter("aFilter", a).filter("bFilter", b);
230229
expect(ngModule.invokeQueue[0]).toEqual([
231-
FILTER_LITERAL,
230+
injectTokens.$filterProvider,
232231
"register",
233232
["aFilter", a],
234233
]);
235234
expect(ngModule.invokeQueue[1]).toEqual([
236-
FILTER_LITERAL,
235+
$injectTokens.$filterProvider,
237236
"register",
238237
["bFilter", b],
239238
]);

0 commit comments

Comments
 (0)