Skip to content

Instantly share code, notes, and snippets.

@basarat
Last active August 18, 2023 20:29
Show Gist options
  • Save basarat/61860d3b035ead022af3dff67df91a8b to your computer and use it in GitHub Desktop.
Save basarat/61860d3b035ead022af3dff67df91a8b 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