29 lines
945 B
TypeScript
29 lines
945 B
TypeScript
|
|
import {isBlank, isPresent, BaseException, CONST, Type} from 'angular2/src/facade/lang';
|
||
|
|
import {Injectable, OptionalMetadata, SkipSelfMetadata, Binding, Injector, bind} from 'angular2/di';
|
||
|
|
import {PipeBinding} from './pipe_binding';
|
||
|
|
import * as cd from 'angular2/src/change_detection/pipes';
|
||
|
|
|
||
|
|
export class ProtoPipes {
|
||
|
|
/**
|
||
|
|
* Map of {@link Pipe} names to {@link Pipe} implementations.
|
||
|
|
*/
|
||
|
|
config: StringMap<string, PipeBinding> = {};
|
||
|
|
|
||
|
|
constructor(bindings: PipeBinding[]) { bindings.forEach(b => this.config[b.name] = b); }
|
||
|
|
|
||
|
|
get(name: string): PipeBinding {
|
||
|
|
var binding = this.config[name];
|
||
|
|
if (isBlank(binding)) throw new BaseException(`Cannot find pipe '${name}'.`);
|
||
|
|
return binding;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export class Pipes implements cd.Pipes {
|
||
|
|
constructor(public proto: ProtoPipes, public injector: Injector) {}
|
||
|
|
|
||
|
|
get(name: string): any {
|
||
|
|
var b = this.proto.get(name);
|
||
|
|
return this.injector.instantiateResolved(b);
|
||
|
|
}
|
||
|
|
}
|