@aurelia/kernel
Advanced tools
Comparing version 2.0.1-dev.202405031042 to 2.0.1-dev.202405110109
@@ -6,2 +6,9 @@ # Change Log | ||
<a name="2.0.0-beta.17"></a> | ||
# 2.0.0-beta.17 (2024-05-11) | ||
### Refactorings: | ||
* **kernel:** mark side effect free (#1964) ([22c8f71](https://github.com/aurelia/aurelia/commit/22c8f71)) | ||
<a name="2.0.0-beta.16"></a> | ||
@@ -8,0 +15,0 @@ # 2.0.0-beta.16 (2024-05-03) |
{ | ||
"name": "@aurelia/kernel", | ||
"version": "2.0.1-dev.202405031042", | ||
"version": "2.0.1-dev.202405110109", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -41,2 +41,3 @@ "module": "dist/esm/index.mjs", | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
@@ -57,4 +58,4 @@ "lint": "eslint --cache --ext .js,.ts src/", | ||
"dependencies": { | ||
"@aurelia/metadata": "2.0.1-dev.202405031042", | ||
"@aurelia/platform": "2.0.1-dev.202405031042" | ||
"@aurelia/metadata": "2.0.1-dev.202405110109", | ||
"@aurelia/platform": "2.0.1-dev.202405110109" | ||
}, | ||
@@ -61,0 +62,0 @@ "devDependencies": { |
211
src/di.ts
@@ -7,4 +7,2 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
initializeTC39Metadata(); | ||
import { isArrayIndex } from './functions'; | ||
@@ -335,105 +333,110 @@ import { createContainer } from './di.container'; | ||
export const DI = { | ||
createContainer, | ||
getDesignParamtypes, | ||
// getAnnotationParamtypes, | ||
// getOrCreateAnnotationParamTypes, | ||
getDependencies: getDependencies, | ||
/** | ||
* creates a decorator that also matches an interface and can be used as a {@linkcode Key}. | ||
* ```ts | ||
* const ILogger = DI.createInterface<Logger>('Logger'); | ||
* container.register(Registration.singleton(ILogger, getSomeLogger())); | ||
* const log = container.get(ILogger); | ||
* log.info('hello world'); | ||
* class Foo { | ||
* constructor( @ILogger log: ILogger ) { | ||
* log.info('hello world'); | ||
* } | ||
* } | ||
* ``` | ||
* you can also build default registrations into your interface. | ||
* ```ts | ||
* export const ILogger = DI.createInterface<Logger>('Logger', builder => builder.cachedCallback(LoggerDefault)); | ||
* const log = container.get(ILogger); | ||
* log.info('hello world'); | ||
* class Foo { | ||
* constructor( @ILogger log: ILogger ) { | ||
* log.info('hello world'); | ||
* } | ||
* } | ||
* ``` | ||
* but these default registrations won't work the same with other decorators that take keys, for example | ||
* ```ts | ||
* export const MyStr = DI.createInterface<string>('MyStr', builder => builder.instance('somestring')); | ||
* class Foo { | ||
* constructor( @optional(MyStr) public readonly str: string ) { | ||
* } | ||
* } | ||
* container.get(Foo).str; // returns undefined | ||
* ``` | ||
* to fix this add this line somewhere before you do a `get` | ||
* ```ts | ||
* container.register(MyStr); | ||
* container.get(Foo).str; // returns 'somestring' | ||
* ``` | ||
* | ||
* - @param configureOrName - supply a string to improve error messaging | ||
*/ | ||
createInterface, | ||
inject, | ||
/** | ||
* Registers the `target` class as a transient dependency; each time the dependency is resolved | ||
* a new instance will be created. | ||
* | ||
* @param target - The class / constructor function to register as transient. | ||
* @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver. | ||
* | ||
* @example ```ts | ||
* // On an existing class | ||
* class Foo { } | ||
* DI.transient(Foo); | ||
* | ||
* // Inline declaration | ||
* const Foo = DI.transient(class { }); | ||
* // Foo is now strongly typed with register | ||
* Foo.register(container); | ||
* ``` | ||
*/ | ||
transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T> { | ||
target.register = function (container: IContainer): IResolver<InstanceType<T>> { | ||
const registration = transientRegistation(target as T, target as T); | ||
return registration.register(container, target); | ||
}; | ||
target.registerInRequestor = false; | ||
return target as T & RegisterSelf<T>; | ||
}, | ||
/** | ||
* Registers the `target` class as a singleton dependency; the class will only be created once. Each | ||
* consecutive time the dependency is resolved, the same instance will be returned. | ||
* | ||
* @param target - The class / constructor function to register as a singleton. | ||
* @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver. | ||
* @example ```ts | ||
* // On an existing class | ||
* class Foo { } | ||
* DI.singleton(Foo); | ||
* | ||
* // Inline declaration | ||
* const Foo = DI.singleton(class { }); | ||
* // Foo is now strongly typed with register | ||
* Foo.register(container); | ||
* ``` | ||
*/ | ||
singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, options: SingletonOptions = defaultSingletonOptions): | ||
T & RegisterSelf<T> { | ||
target.register = function (container: IContainer): IResolver<InstanceType<T>> { | ||
const registration = singletonRegistration(target, target); | ||
return registration.register(container, target); | ||
}; | ||
target.registerInRequestor = options.scoped; | ||
return target as T & RegisterSelf<T>; | ||
}, | ||
}; | ||
export const DI = /*@__PURE__*/ (() => { | ||
// putting this function inside this IIFE as we wants to call it without triggering side effect | ||
initializeTC39Metadata(); | ||
return { | ||
createContainer, | ||
getDesignParamtypes, | ||
// getAnnotationParamtypes, | ||
// getOrCreateAnnotationParamTypes, | ||
getDependencies: getDependencies, | ||
/** | ||
* creates a decorator that also matches an interface and can be used as a {@linkcode Key}. | ||
* ```ts | ||
* const ILogger = DI.createInterface<Logger>('Logger'); | ||
* container.register(Registration.singleton(ILogger, getSomeLogger())); | ||
* const log = container.get(ILogger); | ||
* log.info('hello world'); | ||
* class Foo { | ||
* constructor( @ILogger log: ILogger ) { | ||
* log.info('hello world'); | ||
* } | ||
* } | ||
* ``` | ||
* you can also build default registrations into your interface. | ||
* ```ts | ||
* export const ILogger = DI.createInterface<Logger>('Logger', builder => builder.cachedCallback(LoggerDefault)); | ||
* const log = container.get(ILogger); | ||
* log.info('hello world'); | ||
* class Foo { | ||
* constructor( @ILogger log: ILogger ) { | ||
* log.info('hello world'); | ||
* } | ||
* } | ||
* ``` | ||
* but these default registrations won't work the same with other decorators that take keys, for example | ||
* ```ts | ||
* export const MyStr = DI.createInterface<string>('MyStr', builder => builder.instance('somestring')); | ||
* class Foo { | ||
* constructor( @optional(MyStr) public readonly str: string ) { | ||
* } | ||
* } | ||
* container.get(Foo).str; // returns undefined | ||
* ``` | ||
* to fix this add this line somewhere before you do a `get` | ||
* ```ts | ||
* container.register(MyStr); | ||
* container.get(Foo).str; // returns 'somestring' | ||
* ``` | ||
* | ||
* - @param configureOrName - supply a string to improve error messaging | ||
*/ | ||
createInterface, | ||
inject, | ||
/** | ||
* Registers the `target` class as a transient dependency; each time the dependency is resolved | ||
* a new instance will be created. | ||
* | ||
* @param target - The class / constructor function to register as transient. | ||
* @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver. | ||
* | ||
* @example ```ts | ||
* // On an existing class | ||
* class Foo { } | ||
* DI.transient(Foo); | ||
* | ||
* // Inline declaration | ||
* const Foo = DI.transient(class { }); | ||
* // Foo is now strongly typed with register | ||
* Foo.register(container); | ||
* ``` | ||
*/ | ||
transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T> { | ||
target.register = function (container: IContainer): IResolver<InstanceType<T>> { | ||
const registration = transientRegistation(target as T, target as T); | ||
return registration.register(container, target); | ||
}; | ||
target.registerInRequestor = false; | ||
return target as T & RegisterSelf<T>; | ||
}, | ||
/** | ||
* Registers the `target` class as a singleton dependency; the class will only be created once. Each | ||
* consecutive time the dependency is resolved, the same instance will be returned. | ||
* | ||
* @param target - The class / constructor function to register as a singleton. | ||
* @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver. | ||
* @example ```ts | ||
* // On an existing class | ||
* class Foo { } | ||
* DI.singleton(Foo); | ||
* | ||
* // Inline declaration | ||
* const Foo = DI.singleton(class { }); | ||
* // Foo is now strongly typed with register | ||
* Foo.register(container); | ||
* ``` | ||
*/ | ||
singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, options: SingletonOptions = defaultSingletonOptions): | ||
T & RegisterSelf<T> { | ||
target.register = function (container: IContainer): IResolver<InstanceType<T>> { | ||
const registration = singletonRegistration(target, target); | ||
return registration.register(container, target); | ||
}; | ||
target.registerInRequestor = options.scoped; | ||
return target as T & RegisterSelf<T>; | ||
}, | ||
}; | ||
})(); | ||
export const IContainer = /*@__PURE__*/createInterface<IContainer>('IContainer'); | ||
@@ -440,0 +443,0 @@ export const IServiceLocator = IContainer as unknown as InterfaceSymbol<IServiceLocator>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1082800
18665
+ Added@aurelia/metadata@2.0.1-dev.202405110109(transitive)
+ Added@aurelia/platform@2.0.1-dev.202405110109(transitive)
- Removed@aurelia/metadata@2.0.1-dev.202405031042(transitive)
- Removed@aurelia/platform@2.0.1-dev.202405031042(transitive)