Commit 1205b7b
Fix infinite feedback loop between Action states
Fixes #220.
There is a potentially circular relationship between `Action.isEnabled`
and `Action.isExecuting`. It's valid for users to observe properites on
`Action` and feed the output back into the action state, and in turn
influence `Action.isEnabled`.
This resolves an issue where:
1. The user supplies a condition as the action enabled state
2. Any property derived from the internal `Action.state` is observed
3. Synchronously, the observer updates the user-supplied state property
4. Which updates the internal `state` property
5. Which causes an externally-observable event to fire, returning to
(3), indefinitely.
The reason for this manifesting as an infinite loop, rather than an
infinite recursion, is the internal use of a `replayLazily` in
`Property`: 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 on `Action.isEnabled` and
`Action.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.1 parent 7920f19 commit 1205b7b
File tree
2 files changed
+32
-2
lines changed- Sources
- Tests/ReactiveSwiftTests
2 files changed
+32
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
| 105 | + | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
117 | 147 | | |
118 | 148 | | |
119 | 149 | | |
| |||
0 commit comments