2015-09-08 13:14:57 -04:00
|
|
|
import {Map, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
|
2015-09-10 18:25:36 -04:00
|
|
|
import {Type, isPresent, stringify, isBlank, print} from 'angular2/src/core/facade/lang';
|
2015-09-08 13:14:57 -04:00
|
|
|
import {DirectiveMetadata, ComponentMetadata} from '../core/metadata';
|
2015-10-02 10:37:23 -04:00
|
|
|
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
|
2015-09-08 13:14:57 -04:00
|
|
|
|
|
|
|
export class MockDirectiveResolver extends DirectiveResolver {
|
2015-10-11 01:11:13 -04:00
|
|
|
private _providerOverrides = new Map<Type, any[]>();
|
|
|
|
private viewProviderOverrides = new Map<Type, any[]>();
|
2015-09-08 13:14:57 -04:00
|
|
|
|
|
|
|
resolve(type: Type): DirectiveMetadata {
|
|
|
|
var dm = super.resolve(type);
|
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
var providerOverrides = this._providerOverrides.get(type);
|
|
|
|
var viewProviderOverrides = this.viewProviderOverrides.get(type);
|
2015-09-08 13:14:57 -04:00
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
var providers = dm.providers;
|
|
|
|
if (isPresent(providerOverrides)) {
|
|
|
|
providers = dm.providers.concat(providerOverrides);
|
2015-09-08 13:14:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dm instanceof ComponentMetadata) {
|
2015-10-11 01:11:13 -04:00
|
|
|
var viewProviders = dm.viewProviders;
|
|
|
|
if (isPresent(viewProviderOverrides)) {
|
|
|
|
viewProviders = dm.viewProviders.concat(viewProviderOverrides);
|
2015-09-08 13:14:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return new ComponentMetadata({
|
|
|
|
selector: dm.selector,
|
2015-09-30 23:59:23 -04:00
|
|
|
inputs: dm.inputs,
|
|
|
|
outputs: dm.outputs,
|
2015-09-08 13:14:57 -04:00
|
|
|
host: dm.host,
|
|
|
|
exportAs: dm.exportAs,
|
2015-09-14 18:59:09 -04:00
|
|
|
moduleId: dm.moduleId,
|
2015-09-17 21:45:14 -04:00
|
|
|
queries: dm.queries,
|
2015-09-08 13:14:57 -04:00
|
|
|
changeDetection: dm.changeDetection,
|
2015-10-11 01:11:13 -04:00
|
|
|
providers: providers,
|
|
|
|
viewProviders: viewProviders
|
2015-09-08 13:14:57 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DirectiveMetadata({
|
|
|
|
selector: dm.selector,
|
2015-09-30 23:59:23 -04:00
|
|
|
inputs: dm.inputs,
|
|
|
|
outputs: dm.outputs,
|
2015-09-08 13:14:57 -04:00
|
|
|
host: dm.host,
|
2015-10-11 01:11:13 -04:00
|
|
|
providers: providers,
|
2015-09-08 13:14:57 -04:00
|
|
|
exportAs: dm.exportAs,
|
2015-09-14 18:59:09 -04:00
|
|
|
moduleId: dm.moduleId,
|
2015-09-17 21:45:14 -04:00
|
|
|
queries: dm.queries
|
2015-09-08 13:14:57 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2015-09-08 13:14:57 -04:00
|
|
|
setBindingsOverride(type: Type, bindings: any[]): void {
|
2015-10-11 01:11:13 -04:00
|
|
|
this._providerOverrides.set(type, bindings);
|
2015-09-08 13:14:57 -04:00
|
|
|
}
|
|
|
|
|
2015-10-11 01:11:13 -04:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
2015-09-08 13:14:57 -04:00
|
|
|
setViewBindingsOverride(type: Type, viewBindings: any[]): void {
|
2015-10-11 01:11:13 -04:00
|
|
|
this.viewProviderOverrides.set(type, viewBindings);
|
|
|
|
}
|
|
|
|
|
|
|
|
setProvidersOverride(type: Type, bindings: any[]): void {
|
|
|
|
this._providerOverrides.set(type, bindings);
|
|
|
|
}
|
|
|
|
|
|
|
|
setViewProvidersOverride(type: Type, viewBindings: any[]): void {
|
|
|
|
this.viewProviderOverrides.set(type, viewBindings);
|
2015-09-08 13:14:57 -04:00
|
|
|
}
|
|
|
|
}
|