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.
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.
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.
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. |
6677ac8 to
ae825b7
Compare
This emulates event listeners. Now someone can raise an event without having to know who is listening to the event.