Last active
August 18, 2023 20:29
-
-
Save basarat/61860d3b035ead022af3dff67df91a8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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