public static SubListeners <S> NewSubStateListener <T, S>(this SubListeners <T> self, Func <T, S> getSubState) { var subListener = new SubListeners <S>(getSubState(self.latestSubState)); self.AddStateChangeListener(getSubState, newSubState => { subListener.OnSubstateChanged(newSubState); }); return(subListener); }
public static SubListeners <S> NewSubStateListener <T, S>(this SubListeners <T> self, Func <T, S> getSubState) { var subListener = new SubListeners <S>(getSubState(self.latestSubState)); var ownListenerInParent = self.AddStateChangeListener(getSubState, newSubState => { subListener.OnSubstateChanged(newSubState); }); subListener.SetUnregisterInParentAction(() => { self.innerListeners -= ownListenerInParent; }); return(subListener); }