Skip to content

Commit 9826c52

Browse files
committed
feat(enabling-cond): fix monotonic time update
1 parent c170777 commit 9826c52

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/store.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::sync::OnceLock;
22

33
use crate::{
4-
ActionId, ActionMeta, ActionWithMeta, Effects, EnablingCondition, Instant, Reducer, SystemTime,
5-
TimeService, SubStore,
4+
ActionId, ActionMeta, ActionWithMeta, Effects, EnablingCondition, Instant, Reducer, SubStore,
5+
SystemTime, TimeService,
66
};
77

88
/// Wraps around State and allows only immutable borrow,
@@ -158,7 +158,10 @@ where
158158
<Self as SubStore<State, S>>::SubAction: Into<Action>,
159159
Self: SubStore<State, S>,
160160
{
161-
if !action.is_enabled(<Self as SubStore<State, S>>::state(self), self.last_action_id.into()) {
161+
if !action.is_enabled(
162+
<Self as SubStore<State, S>>::state(self),
163+
self.last_action_id.into(),
164+
) {
162165
return false;
163166
}
164167
self.dispatch_enabled(action.into().into());
@@ -172,12 +175,16 @@ where
172175
let time_passed = monotonic_time
173176
.duration_since(self.monotonic_time)
174177
.as_nanos();
178+
self.monotonic_time = monotonic_time;
179+
175180
let prev = self.last_action_id;
176-
self.last_action_id = prev.next(time_passed as u64);
177-
self.recursion_depth += 1;
181+
let curr = prev.next(time_passed as u64);
178182

179183
let action_with_meta =
180-
ActionMeta::new(self.last_action_id, prev, self.recursion_depth).with_action(action);
184+
ActionMeta::new(curr, prev, self.recursion_depth).with_action(action);
185+
186+
self.last_action_id = curr;
187+
self.recursion_depth += 1;
181188

182189
self.dispatch_reducer(&action_with_meta);
183190
self.dispatch_effects(action_with_meta);

0 commit comments

Comments
 (0)