Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

loosen typings on context for a Injector #631

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,21 @@ export interface InjectorProperties extends WidgetProperties {
children: DNode[];
}

export class BaseInjector<C extends Evented = Context> extends WidgetBase<InjectorProperties> {
export interface Base<C = Context> {
toInject(): C;
}

export class Base<C = Context> extends WidgetBase<InjectorProperties> implements Base<C> {

protected context: C = <C> {};

public toInject(): C {
return this.context;
}
}

export class BaseInjector<C extends Evented = Context> extends Base<C> {

constructor(context?: C) {
super();
if (context) {
Expand All @@ -85,16 +96,13 @@ export class BaseInjector<C extends Evented = Context> extends WidgetBase<Inject
}
}

public toInject(): C {
return this.context;
}
}

/**
* Mixin that extends the supplied Injector class with the proxy `render` and passing the provided to `context` to the Injector
* class via the constructor.
*/
export function Injector<C extends Evented, T extends Constructor<BaseInjector<C>>>(Base: T, context: C): T {
export function Injector<C, T extends Constructor<Base<C>>>(Base: T, context: C): T {

@diffProperty('render', always)
class Injector extends Base {
Expand Down