Closed trowski closed 7 years ago
I don't think changing the behavior depending on whether an event has been created before Loop::execute
or not is a good idea.
@kelunik The current behavior preserves the state of Loop
before Loop::execute()
is invoked (updated changes summary to make this clear). However, I considered leaving the driver that was created as the active driver after Loop::execute()
returns. I'd like to hear more feedback on this point.
Closing in favor of @bwoebi's proposal in this comment.
In the spirit of @davidwdan's PR #142, this PR allows the creation of loop events outside an execute context, however it still allows stacking of event loops and provides for consistent testing environments. The model here is inspired by @WyriHaximus's comment, allowing for both the React-style and Amp-style of creating events in the event loop.
With these changes both of the models below work as expected.
Both will output:
Summary of Changes
Loop::execute()
now runs the currently active loop driver when invoked, allowing events to be created outside a running event loop.Loop::execute()
is now optional.Loop::resetDriver()
allows the active loop driver instance to be nulled if a loop is not running, allowing tests to easily reset the environment.Loop::execute()
is invoked, the driver instance will automatically be set to null whenLoop::execute()
returns. If an active driver instance exists whenLoop::execute()
is invoked, that instance will remain as the active driver afterLoop::execute()
returns. This behavior preserves the state ofLoop
before and afterLoop::execute()
is invoked.Loop::createDriver()
is now public to allow usage as the second parameter toLoop::execute()
.Loop::execute()
reuse the same active driver unless an a new instance is provided as the second parameter.Loop::setFactory()
does not reset the active driver instance.