-
Notifications
You must be signed in to change notification settings - Fork 147
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
BehavioralFsm event emitter and clients #107
Comments
IMO, that's not what the current API is intending. Normally, you would attach only one listener for all FSMs. Not one listener per FSM.
|
@kkirby Hey - just wanted to drop you a note to say I plan to follow up with a reply, just been a crazy week! Once I get a second to actually sit down and think I'll touch base! :-) |
Aaaand 2 years just flew by in an instant. I wish I could pretend I'm a time traveler, but alas, #146 explains that's not the case. 😺 For our future fellow devs that find themselves with similar questions, my current recommendation is along the lines of what @j-ulrich suggested: attach one listener to the behavioral FSM and then you can control the responsibilities from there. I'm not opposed to revisiting this issue in the future - but some real world use cases would be super helpful! |
Hello,
I had a question about how
BehavioralFsm
emits events. I was reading the code and saw that all events from any client are emitted on theBehavioralFsm
instance (which makes sense). But let's say I have 200 instances of a class that utilize aBehavioralFsm
, and I want to listen totransition
events. Whenever any statemachine transitions, all listeners will be called even if they don't care so much because they aren't concerned with theFsm
that transitioned. I know you could do an if check on theclient
event argument property to see if it is equal tothis
, but having to run that check 200 times on a single event is a bit intense and unnecessary logic. Is there anyway around this? Perhaps a method signature likeon(client,event)
? I'm pretty sure it doesn't exist, but wouldmachina.js
give open arms to a pull request that implemented this functionality? If so, are there any gotchas I should know about before implementing such functionality?I would was thinking of implementing it using a
WeakMap
and when anemitEvent
was called, the client would be looked up in theWeakMap
to determine the listeners.The text was updated successfully, but these errors were encountered: