40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
declare type TypeCTXRef = {
|
|
[key: string]: any;
|
|
};
|
|
export interface ICTXFN {
|
|
(context: Context): any;
|
|
}
|
|
interface Init {
|
|
(ctxRef?: TypeCTXRef, parentContext?: Context | void): TypeCTXRef | null;
|
|
}
|
|
declare type ContextOptions = {
|
|
use: () => Context | void;
|
|
set: (value: any) => any;
|
|
addQueryableProperties: (ctxRef: TypeCTXRef) => TQueryableProperties;
|
|
init?: Init;
|
|
};
|
|
declare type TQueryableProperties = {
|
|
[key: string]: true;
|
|
};
|
|
export declare type TCTX = {
|
|
use: () => Context | void;
|
|
run: (ctxRef: TypeCTXRef, fn: ICTXFN) => any;
|
|
bind: (ctxRef: TypeCTXRef, fn: (...args: any[]) => any, ...args: any[]) => (...runTimeArgs: any[]) => any;
|
|
};
|
|
declare class Context {
|
|
private _parentContext;
|
|
[key: string]: any;
|
|
static is(value: any): value is Context;
|
|
constructor({ use, set, addQueryableProperties, init }: ContextOptions, ctxRef: TypeCTXRef);
|
|
addLookupProperty(key: string): void;
|
|
private lookup;
|
|
private setParentContext;
|
|
get parentContext(): Context | null;
|
|
}
|
|
declare function createContext(init?: Init): {
|
|
use: () => Context | void;
|
|
run: (ctxRef: TypeCTXRef, fn: ICTXFN) => any;
|
|
bind: (ctxRef: TypeCTXRef, fn: (...args: any[]) => any, ...args: any[]) => (...runTimeArgs: any[]) => any;
|
|
};
|
|
export default createContext;
|