Stl.Fusion
Stl.Fusion copied to clipboard
how to correctly subscribe to an ComputedState<T> state value without inheriting from ComputedStateComponent<T>?
Could you please provide me with an example?
hey mate. this has been moved to https://github.com/ActualLab/Fusion
@extential thanks, your're right.
@neozhu I'll post a quick answer: see how IState<T>.When
and IState<T>.Changes
methods are implemented ( https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Fusion/State/StateExt.cs#L81 ). Overall, they call identical methods on State.Computed
, which can be found here: https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Fusion/ComputedExt.cs#L175
And that's nearly the logic you need to observe IState<T>
changes. Or simply use await foreach (var computed in state.Changes(...))
or await foreach (value, error) in state.Changes(...))
. Computed<T>
implements IResult<T>
, which means it can be deconstructed to (T value, Exception? error)
.