-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Split code into separate files for better tree-shaking (#35)
- Loading branch information
1 parent
49097b4
commit b8f1ce0
Showing
25 changed files
with
177 additions
and
137 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import DependencyContainer from "../types/dependency-container"; | ||
|
||
type FactoryFunction<T> = (dependencyContainer: DependencyContainer) => T; | ||
|
||
export default FactoryFunction; |
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,5 @@ | ||
export {default as FactoryFunction} from "./factory-function"; | ||
export {default as instanceCachingFactory} from "./instance-caching-factory"; | ||
export { | ||
default as predicateAwareClassFactory | ||
} from "./predicate-aware-class-factory"; |
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,14 @@ | ||
import DependencyContainer from "../types/dependency-container"; | ||
import FactoryFunction from "./factory-function"; | ||
|
||
export default function instanceCachingFactory<T>( | ||
factoryFunc: FactoryFunction<T> | ||
): FactoryFunction<T> { | ||
let instance: T; | ||
return (dependencyContainer: DependencyContainer) => { | ||
if (instance == undefined) { | ||
instance = factoryFunc(dependencyContainer); | ||
} | ||
return instance; | ||
}; | ||
} |
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 was deleted.
Oops, something went wrong.
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,12 @@ | ||
import constructor from "../types/constructor"; | ||
import Provider from "./provider"; | ||
|
||
export default interface ClassProvider<T> { | ||
useClass: constructor<T>; | ||
} | ||
|
||
export function isClassProvider<T>( | ||
provider: Provider<T> | ||
): provider is ClassProvider<any> { | ||
return !!(<ClassProvider<T>>provider).useClass; | ||
} |
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,17 @@ | ||
import DependencyContainer from "../types/dependency-container"; | ||
import Provider from "./provider"; | ||
|
||
/** | ||
* Provide a dependency using a factory. | ||
* Unlike the other providers, this does not support instance caching. If | ||
* you need instance caching, your factory method must implement it. | ||
*/ | ||
export default interface FactoryProvider<T> { | ||
useFactory: (dependencyContainer: DependencyContainer) => T; | ||
} | ||
|
||
export function isFactoryProvider<T>( | ||
provider: Provider<T> | ||
): provider is FactoryProvider<any> { | ||
return !!(<FactoryProvider<T>>provider).useFactory; | ||
} |
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,9 @@ | ||
export {default as ClassProvider, isClassProvider} from "./class-provider"; | ||
export { | ||
default as FactoryProvider, | ||
isFactoryProvider | ||
} from "./factory-provider"; | ||
export {default as InjectionToken, isNormalToken} from "./injection-token"; | ||
export {default as Provider} from "./provider"; | ||
export {default as TokenProvider, isTokenProvider} from "./token-provider"; | ||
export {default as ValueProvider, isValueProvider} from "./value-provider"; |
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,11 @@ | ||
import constructor from "../types/constructor"; | ||
|
||
type InjectionToken<T = any> = constructor<T> | string | symbol; | ||
|
||
export function isNormalToken( | ||
token?: InjectionToken<any> | ||
): token is string | symbol { | ||
return typeof token === "string" || typeof token === "symbol"; | ||
} | ||
|
||
export default InjectionToken; |
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,12 @@ | ||
import ClassProvider from "./class-provider"; | ||
import ValueProvider from "./value-provider"; | ||
import TokenProvider from "./token-provider"; | ||
import FactoryProvider from "./factory-provider"; | ||
|
||
type Provider<T> = | ||
| ClassProvider<T> | ||
| ValueProvider<T> | ||
| TokenProvider<T> | ||
| FactoryProvider<T>; | ||
|
||
export default Provider; |
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,12 @@ | ||
import InjectionToken from "./injection-token"; | ||
import Provider from "./provider"; | ||
|
||
export default interface TokenProvider<T> { | ||
useToken: InjectionToken<T>; | ||
} | ||
|
||
export function isTokenProvider<T>( | ||
provider: Provider<T> | ||
): provider is TokenProvider<any> { | ||
return !!(<TokenProvider<T>>provider).useToken; | ||
} |
Oops, something went wrong.