Skip to content

Commit

Permalink
Bizarre DisplayObject.dispatch mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
hubol committed Jul 30, 2024
1 parent c62aa0c commit 2523270
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/extensions/-load-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./pixi-color";
import "./pixi-container-flip";
import "./pixi-displayobject-async";
import "./pixi-displayobject-convenience";
import "./pixi-displayobject-dispatch";
import "./pixi-displayobject-mixin";
import "./pixi-displayobject-ticker";
import "./pixi-displayobject-track";
Expand Down
36 changes: 36 additions & 0 deletions src/lib/extensions/pixi-displayobject-dispatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DisplayObject } from "pixi.js";

interface DispatchingDisplayObject<TEvent extends string> {
dispatch(event: TEvent): void;
handles(event: TEvent, fn: (self: this) => unknown): this;
}

declare module "pixi.js" {
interface DisplayObject {
dispatches<TEvent extends string>(): this & DispatchingDisplayObject<TEvent>;
}
}

Object.defineProperties(DisplayObject.prototype, {
dispatches: {
value: function (this: DisplayObject) {
return this;
},
configurable: true,
},
dispatch: {
value: function (this: DisplayObject, event: string) {
this.emit(event, this);
},
configurable: true,
},
handles: {
value: function (this: DisplayObject, event: string, fn: (self: any) => unknown) {
this.on(event, fn);
return this;
},
configurable: true,
},
});

export default 0;

0 comments on commit 2523270

Please sign in to comment.