-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove openbim-components dependency
- Loading branch information
Showing
10 changed files
with
2,037 additions
and
164,611 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Simple event handler by | ||
* [Jason Kleban](https://gist.github.com/JasonKleban/50cee44960c225ac1993c922563aa540). | ||
* Keep in mind that: | ||
* - If you want to remove it later, you might want to declare the callback as | ||
* an object. | ||
* - If you want to maintain the reference to `this`, you will need to declare | ||
* the callback as an arrow function. | ||
*/ | ||
export class Event<T> { | ||
/** | ||
* Add a callback to this event instance. | ||
* @param handler - the callback to be added to this event. | ||
*/ | ||
add(handler: T extends void ? { (): void } : { (data: T): void }): void { | ||
this.handlers.push(handler); | ||
} | ||
|
||
/** | ||
* Removes a callback from this event instance. | ||
* @param handler - the callback to be removed from this event. | ||
*/ | ||
remove(handler: T extends void ? { (): void } : { (data: T): void }): void { | ||
this.handlers = this.handlers.filter((h) => h !== handler); | ||
} | ||
|
||
/** Triggers all the callbacks assigned to this event. */ | ||
trigger = async (data?: T) => { | ||
const handlers = this.handlers.slice(0); | ||
for (const handler of handlers) { | ||
await handler(data as any); | ||
} | ||
}; | ||
|
||
/** Gets rid of all the suscribed events. */ | ||
reset() { | ||
this.handlers.length = 0; | ||
} | ||
|
||
private handlers: (T extends void ? { (): void } : { (data: T): void })[] = | ||
[]; | ||
} |
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
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
Oops, something went wrong.