But do it during the build process for cjs. Right now we only need this when we transpile from ts directly to es5. This is only the case in our cis build, as for our browser build we only transpile from ts to es6 via ts and then use traceur to do the rest.
26 lines
876 B
TypeScript
26 lines
876 B
TypeScript
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
|
import {isBlank, isPresent, BaseException, CONST} from 'angular2/src/facade/lang';
|
|
import {Pipe} from './pipe';
|
|
import {Injectable} from 'angular2/src/di/decorators';
|
|
import {ChangeDetectorRef} from '../change_detector_ref';
|
|
|
|
@Injectable()
|
|
export class PipeRegistry {
|
|
constructor(public config) {}
|
|
|
|
get(type: string, obj, cdRef: ChangeDetectorRef): Pipe {
|
|
var listOfConfigs = this.config[type];
|
|
if (isBlank(listOfConfigs)) {
|
|
throw new BaseException(`Cannot find '${type}' pipe supporting object '${obj}'`);
|
|
}
|
|
|
|
var matchingConfig = ListWrapper.find(listOfConfigs, (pipeConfig) => pipeConfig.supports(obj));
|
|
|
|
if (isBlank(matchingConfig)) {
|
|
throw new BaseException(`Cannot find '${type}' pipe supporting object '${obj}'`);
|
|
}
|
|
|
|
return matchingConfig.create(cdRef);
|
|
}
|
|
}
|