Skip to content

Instantly share code, notes, and snippets.

@hiukky
Forked from basarat/mixin.ts
Created July 14, 2021 21:02
Show Gist options
  • Save hiukky/01f22c030cdb610a8855b553c2473ae3 to your computer and use it in GitHub Desktop.
Save hiukky/01f22c030cdb610a8855b553c2473ae3 to your computer and use it in GitHub Desktop.
export type Class = new (...args: any[]) => any;
export function DisposableMixin<Base extends Class>(base: Base) {
return class extends base {
isDisposed: boolean = false;
dispose() {
this.isDisposed = true;
}
};
}
export function ActivatableMixin<Base extends Class>(base: Base) {
return class extends base {
isActive: boolean = false;
activate() {
this.isActive = true;
}
deactivate() {
this.isActive = false;
}
};
}
class Example extends DisposableMixin(ActivatableMixin(class { })) {
member = 123;
constructor() {
super();
}
}
const example: Example = new Example();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment