Skip to content

Commit

Permalink
fix: restored listener events
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelOsborne committed Dec 14, 2024
1 parent 2ee6da2 commit 107ae6e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions dotlottie-rs/src/state_machine_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,14 @@ impl StateMachineEngine {
let new_state = self.get_state(state_name);

// We have a new state
if new_state.is_some() {
if let Some(new_state) = new_state {
// Emit transtion occured event
if let Ok(observers) = self.observers.try_read() {
for observer in observers.iter() {
observer.on_transition(self.get_current_state_name(), new_state.name());
}
}

// Perform exit actions on the current state if there is one.
if self.current_state.is_some() {
let state = self.current_state.take();
Expand All @@ -517,8 +524,22 @@ impl StateMachineEngine {
}
}

// Emit transtion occured event
if let Ok(observers) = self.observers.try_read() {
for observer in observers.iter() {
observer.on_state_exit(self.get_current_state_name());
}
}

// Assign the new state to the current_state
self.current_state = new_state;
self.current_state = Some(new_state);

// Emit transtion occured event
if let Ok(observers) = self.observers.try_read() {
for observer in observers.iter() {
observer.on_state_entered(self.get_current_state_name());
}
}

// Perform entry actions
// Execute its type of state
Expand Down

0 comments on commit 107ae6e

Please sign in to comment.