You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
import Instantiable from '../../../di/src/type/Instantiable.ts'
|
|
import {DependencyKey} from '../../../di/src/type/DependencyKey.ts'
|
|
import {make} from '../../../di/src/global.ts'
|
|
import Application from '../lifecycle/Application.ts'
|
|
|
|
export interface Bindable {
|
|
get_bound_method(method_name: string): (...args: any[]) => any
|
|
}
|
|
|
|
export function isBindable(what: any): what is Bindable {
|
|
return (
|
|
what
|
|
&& typeof what.get_bound_method === 'function'
|
|
&& what.get_bound_method.length === 1
|
|
&& typeof what.get_bound_method('get_bound_method') === 'function'
|
|
)
|
|
}
|
|
|
|
export default class AppClass {
|
|
protected static make<T>(target: Instantiable<T>|DependencyKey, ...parameters: any[]) {
|
|
return make(target, ...parameters)
|
|
}
|
|
|
|
protected static get app() {
|
|
return make(Application)
|
|
}
|
|
|
|
protected make<T>(target: Instantiable<T>|DependencyKey, ...parameters: any[]) {
|
|
return make(target, ...parameters)
|
|
}
|
|
|
|
protected get app() {
|
|
return make(Application)
|
|
}
|
|
|
|
public get_bound_method(method_name: string): (...args: any[]) => any {
|
|
// @ts-ignore
|
|
if ( typeof this[method_name] !== 'function' ) {
|
|
throw new TypeError(`Attempt to get bound method for non-function type: ${method_name}`)
|
|
}
|
|
|
|
return (...args: any[]): any => {
|
|
// @ts-ignore
|
|
return this[method_name](...args)
|
|
}
|
|
}
|
|
}
|