feat(ivy): add canonical example of a pipe. (#21834)

PR Close #21834
This commit is contained in:
Misko Hevery
2018-01-27 13:07:03 -08:00
committed by Alex Rickabaugh
parent f816666ede
commit 743d8bc845
6 changed files with 243 additions and 5 deletions

View File

@ -7,13 +7,14 @@
*/
import {SimpleChange} from '../change_detection/change_detection_util';
import {PipeTransform} from '../change_detection/pipe_transform';
import {OnChanges, SimpleChanges} from '../metadata/lifecycle_hooks';
import {RendererType2} from '../render/api';
import {Type} from '../type';
import {resolveRendererType2} from '../view/util';
import {diPublic} from './di';
import {ComponentDef, ComponentDefArgs, DirectiveDef, DirectiveDefArgs} from './interfaces/definition';
import {ComponentDef, ComponentDefArgs, DirectiveDef, DirectiveDefArgs, PipeDef, PipeType} from './interfaces/definition';
@ -26,7 +27,7 @@ import {ComponentDef, ComponentDefArgs, DirectiveDef, DirectiveDefArgs} from './
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static [COMPONENT_DEF_SYMBOL] = defineComponent({
* static ngComponentDef = defineComponent({
* ...
* });
* }
@ -147,7 +148,7 @@ function invertObject(obj: any): any {
* class MyDirective {
* // Generated by Angular Template Compiler
* // [Symbol] syntax will not be supported by TypeScript until v2.7
* static [DIRECTIVE_DEF_SYMBOL] = defineDirective({
* static ngDirectiveDef = defineDirective({
* ...
* });
* }
@ -155,3 +156,25 @@ function invertObject(obj: any): any {
*/
export const defineDirective = defineComponent as<T>(directiveDefinition: DirectiveDefArgs<T>) =>
DirectiveDef<T>;
/**
* Create a pipe definition object.
*
* # Example
* ```
* class MyPipe implements PipeTransform {
* // Generated by Angular Template Compiler
* static ngPipeDef = definePipe({
* ...
* });
* }
* ```
* @param type Pipe class reference. Needed to extract pipe lifecycle hooks.
* @param factory A factory for creating a pipe instance.
* @param pure Whether the pipe is pure.
*/
export function definePipe<T>(
{type, factory, pure}: {type: Type<T>, factory: () => PipeTransform, pure?: boolean}):
PipeDef<T> {
throw new Error('TODO: implement!');
}