Skip to content

Commit

Permalink
Added a substate AddStateChangeListener that allows to register a lis…
Browse files Browse the repository at this point in the history
…tener for the entire substate
  • Loading branch information
cs-util committed Nov 16, 2023
1 parent 816af7d commit fda8f71
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public void TriggerOnSubstateChanged(S newSubState) {
onStateChanged?.Invoke();
}

public Action AddStateChangeListener(Action<S> onChanged, bool triggerInstantToInit = true) {
Action newListener = ImmutableExtensions.NewSubstateChangeListener(() => {
this.ThrowErrorIfDisposed();
return GetState();
}, onChanged);
onStateChanged += newListener;
if (triggerInstantToInit) { onChanged(GetState()); }
return newListener;
}

public Action AddStateChangeListener<SubSub>(Func<S, SubSub> getSubSubState, Action<SubSub> onChanged, bool triggerInstantToInit = true) {
Action newListener = ImmutableExtensions.NewSubstateChangeListener(() => {
this.ThrowErrorIfDisposed();
Expand Down

0 comments on commit fda8f71

Please sign in to comment.