-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and remove config from factory functions
- Loading branch information
Showing
13 changed files
with
127 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ServiceIdentifier } from './types'; | ||
|
||
import { DESIGN_PARAM_TYPES } from './utils'; | ||
|
||
declare var Reflect: any; | ||
|
||
export function InjectMany<Dependency>(serviceIdentifiers: Array<ServiceIdentifier<Dependency>>) { | ||
return (target: any, _targetKey: any, index: number) => { | ||
let dependencies = Reflect.getMetadata(DESIGN_PARAM_TYPES, target) || []; | ||
if (!dependencies) { | ||
throw new Error('You must decorate the provider class with @Injectable()'); | ||
} | ||
if (typeof index === 'number') { | ||
dependencies[index] = serviceIdentifiers; | ||
} else { | ||
dependencies = serviceIdentifiers; | ||
} | ||
Reflect.defineMetadata(DESIGN_PARAM_TYPES, dependencies, target); | ||
return target; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ServiceIdentifier, Provider, Type, ValueProvider, ClassProvider, FactoryProvider, TypeProvider } from './types'; | ||
|
||
export const DESIGN_PARAM_TYPES = 'design:paramtypes'; | ||
|
||
export function getServiceIdentifierName<T>(serviceIdentifier: ServiceIdentifier<T>) { | ||
if (typeof serviceIdentifier === 'function' && isType<T>(serviceIdentifier)) { | ||
return serviceIdentifier.name; | ||
} else { | ||
return serviceIdentifier.toString(); | ||
} | ||
} | ||
|
||
export function isType<T>(v: any): v is Type<T> { | ||
return typeof v === 'function' && 'prototype' in v; | ||
} | ||
|
||
export function isTypeProvider<T>(v: Provider<T>): v is TypeProvider<T> { | ||
return isType<T>(v); | ||
} | ||
|
||
export function isValueProvider<T>(v: Provider<T>): v is ValueProvider<T> { | ||
return 'useValue' in v; | ||
} | ||
|
||
export function isClassProvider<T>(v: Provider<T>): v is ClassProvider<T> { | ||
return 'useClass' in v && isType(v.useClass); | ||
} | ||
|
||
export function isFactoryProvider<T>(v: Provider<T>): v is FactoryProvider<T> { | ||
return 'useFactory' in v && typeof v.useFactory === 'function'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.