2015-08-20 14:28:25 -07:00
|
|
|
import {isBlank, isPresent, BaseException, CONST, Type} from 'angular2/src/core/facade/lang';
|
2015-08-07 11:41:38 -07:00
|
|
|
import {Injectable, OptionalMetadata, SkipSelfMetadata, Binding, Injector, bind} from 'angular2/di';
|
|
|
|
|
import {PipeBinding} from './pipe_binding';
|
2015-08-20 14:28:25 -07:00
|
|
|
import * as cd from 'angular2/src/core/change_detection/pipes';
|
2015-08-07 11:41:38 -07:00
|
|
|
|
|
|
|
|
export class ProtoPipes {
|
|
|
|
|
/**
|
2015-08-14 10:03:45 -07:00
|
|
|
* Map of {@link PipeMetadata} names to {@link PipeMetadata} implementations.
|
2015-08-07 11:41:38 -07:00
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|