-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
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
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,50 @@ | ||
import { Event } from "./event"; | ||
import { AsyncEvent } from "./async-event"; | ||
|
||
/** | ||
* Simple class to easily toggle and reset event lists. | ||
*/ | ||
export class EventManager { | ||
/** | ||
* The list of events managed by this instance. | ||
*/ | ||
list = new Set<Event<any> | AsyncEvent<any>>(); | ||
|
||
/** | ||
* Adds events to this manager. | ||
* @param events the events to add. | ||
*/ | ||
add(events: Iterable<Event<any> | AsyncEvent<any>>) { | ||
for (const event of events) { | ||
this.list.add(event); | ||
} | ||
} | ||
/** | ||
* Removes events from this manager. | ||
* @param events the events to remove. | ||
*/ | ||
remove(events: Iterable<Event<any> | AsyncEvent<any>>) { | ||
for (const event of events) { | ||
this.list.delete(event); | ||
} | ||
} | ||
|
||
/** | ||
* Sets all the events managed by this instance as enabled or disabled. | ||
* @param active whether to turn on or off the events. | ||
*/ | ||
set(active: boolean) { | ||
for (const event of this.list) { | ||
event.enabled = active; | ||
} | ||
} | ||
|
||
/** | ||
* Resets all the events managed by this instance. | ||
*/ | ||
reset() { | ||
for (const event of this.list) { | ||
event.reset(); | ||
} | ||
} | ||
} |
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