-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add MSU.Class.Event class #321
base: development
Are you sure you want to change the base?
Conversation
This emulates event listeners. Now someone can raise an event without having to know who is listening to the event.
// Will iterate over every registered function and check _conditionFunction | ||
// if _conditionFunction returns false, stops iteration immediately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels to me like this should perhaps be based on the actual functions that are being called,ie if they return false
then stop or something along those lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, those functions can be anything. They don't necessarily have to be Boolean returning functions. This conditionalInvoke
is more along the lines of replicating the isAlive
feature of skill_container events where the iteration stops if the actor is no longer alive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning false to stop an event from continuing feels quite natural, it's how it's done in JS event bubbling for example. Using some otherwise decoupled thing to check for a state is weird in contrast.
Do we have an usecase for this? |
I mean event listeners are a basic thing in programming and I'm sure people will find use cases for this. It will help modders write more decoupled code. |
I'm wondering if keeping the env around like that doesn't lead to a risk of memory leaks. |
Also, if this shouldn't keep a dict of events, with arrays for each of course. |
This emulates event listeners. Now someone can raise an event without having to know who is listening to the event.