Fix infinite feedback loop between Action states #221
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #220.
There is a potentially circular relationship between
Action.isEnabled
andAction.isExecuting
. It's valid for users to observe properites onAction
and feed the output back into the action state, and in turn influenceAction.isEnabled
.This resolves an issue where:
Action.state
is observedstate
propertyThe reason for this manifesting as an infinite loop, rather than an infinite recursion, is the internal use of a
replayLazily
inProperty
: each time a side effect on the user-supplied property occurs, that queues up another event inside the replayed signal producer, and the observer is never attached because there is always a buffered event to consume.The issue was that multiple events were firing synchronously when observing
Action.isExecuting
, even though the executing state had never changed. The fix is to skip repeats onAction.isEnabled
andAction.isExecuting
, so that observers are only ever notified if the value actually changes, instead of whenever something triggeres a side-effect on the internal state.