-
Notifications
You must be signed in to change notification settings - Fork 171
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
store root dispatcher in a static var #780
store root dispatcher in a static var #780
Conversation
This seems to be the safest way to store the main dispatcher. Using context to store the main event dispatcher causes a scope to be created: activating the newly-created context which stores dispatcher causes a new scope, and that can break things. I also looked at storing dispatcher in the root context, but that can't work because contexts are immutable.
Codecov Report
@@ Coverage Diff @@
## main #780 +/- ##
============================================
- Coverage 79.53% 79.49% -0.05%
+ Complexity 1409 1407 -2
============================================
Files 160 160
Lines 3479 3472 -7
============================================
- Hits 2767 2760 -7
Misses 712 712
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
/** @var array<string, array<int, array<callable>>> */ | ||
private array $listeners = []; | ||
|
||
public static function getInstance(): self | ||
public static function getRoot(): self |
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.
I chose root
because it sounds less singleton-y, since you can in fact have as many dispatchers as you wish. This is just the default one.
Oki. |
This seems to be the safest way to store the main dispatcher. Using context to store the main event dispatcher causes a scope to be created: activating the newly-created context which stores dispatcher causes a new scope, and that can break things.
I also looked at storing dispatcher in the root context, but that can't work because contexts are immutable.
Closes #778