2015-02-12 14:56:41 -08:00
|
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
import {isBlank, isPresent, BaseException, CONST} from 'angular2/src/facade/lang';
|
|
|
|
import {Pipe} from './pipe';
|
2015-04-14 07:47:12 -07:00
|
|
|
import {ChangeDetectorRef} from '../change_detector_ref';
|
2015-02-12 14:56:41 -08:00
|
|
|
|
|
|
|
export class PipeRegistry {
|
|
|
|
config;
|
|
|
|
|
|
|
|
constructor(config){
|
|
|
|
this.config = config;
|
|
|
|
}
|
|
|
|
|
2015-04-14 07:47:12 -07:00
|
|
|
get(type:string, obj, cdRef:ChangeDetectorRef):Pipe {
|
2015-02-12 14:56:41 -08:00
|
|
|
var listOfConfigs = this.config[type];
|
|
|
|
if (isBlank(listOfConfigs)) {
|
|
|
|
throw new BaseException(`Cannot find a pipe for type '${type}' object '${obj}'`);
|
|
|
|
}
|
|
|
|
|
|
|
|
var matchingConfig = ListWrapper.find(listOfConfigs,
|
2015-02-19 17:47:25 -08:00
|
|
|
(pipeConfig) => pipeConfig.supports(obj));
|
2015-02-12 14:56:41 -08:00
|
|
|
|
|
|
|
if (isBlank(matchingConfig)) {
|
|
|
|
throw new BaseException(`Cannot find a pipe for type '${type}' object '${obj}'`);
|
|
|
|
}
|
|
|
|
|
2015-04-14 07:47:12 -07:00
|
|
|
return matchingConfig.create(cdRef);
|
2015-02-12 14:56:41 -08:00
|
|
|
}
|
|
|
|
}
|