From fda8f715156fba69a7e05be0fe99c53ab3bd8d61 Mon Sep 17 00:00:00 2001 From: S Date: Thu, 16 Nov 2023 08:04:40 +0100 Subject: [PATCH] Added a substate AddStateChangeListener that allows to register a listener for the entire substate --- .../CsCore/com/csutil/model/immutable/SubState.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CsCore/PlainNetClassLib/src/Plugins/CsCore/com/csutil/model/immutable/SubState.cs b/CsCore/PlainNetClassLib/src/Plugins/CsCore/com/csutil/model/immutable/SubState.cs index 57a02443..cdb08148 100644 --- a/CsCore/PlainNetClassLib/src/Plugins/CsCore/com/csutil/model/immutable/SubState.cs +++ b/CsCore/PlainNetClassLib/src/Plugins/CsCore/com/csutil/model/immutable/SubState.cs @@ -48,6 +48,16 @@ public void TriggerOnSubstateChanged(S newSubState) { onStateChanged?.Invoke(); } + public Action AddStateChangeListener(Action onChanged, bool triggerInstantToInit = true) { + Action newListener = ImmutableExtensions.NewSubstateChangeListener(() => { + this.ThrowErrorIfDisposed(); + return GetState(); + }, onChanged); + onStateChanged += newListener; + if (triggerInstantToInit) { onChanged(GetState()); } + return newListener; + } + public Action AddStateChangeListener(Func getSubSubState, Action onChanged, bool triggerInstantToInit = true) { Action newListener = ImmutableExtensions.NewSubstateChangeListener(() => { this.ThrowErrorIfDisposed();