Closed houstonhaynes closed 1 year ago
Hold the phone - IsAutoUpdating is not being set... let me spend a bit more time with it in the morning with a fresh pair of brain cells. š
I think you need to move the condition into the list comprehension:
let subscriptions (model: Model) : Sub<Msg> =
let autoUpdateSubscription (dispatch: Msg -> unit) =
let timer = new Timer(1000)
timer.Elapsed.Add(fun _ ->
// similar to newSeries create null entry in 1% of cases
let randomNull = rnd.Next(0, 99)
match randomNull with
| i when i = 0 ->
dispatch AddNull
| _ -> dispatch AddItem
dispatch RemoveItem
)
timer.Start()
timer :> IDisposable
[
if model.IsAutoUpdating then
[ nameof autoUpdateSubscription ], autoUpdateSubscription
]
This is brilliant! Thanks. I was a bit sheepish about where that might go - and grokking the role of the list comprehension helps.
Just to be pedantically clear, the original version of this with the let mutable isUpdating
the loop was always "running" - i.e. the loop starts as the view initializes. Is this correct?
And if I'm reading this correctly, this has now changed with the if
within the list comprehension such that the loop "starts from a cold start" when model.IsAutoUpdating
is set to true.
So this in effect actually makes the app comparatively more efficient as well as more "pure" by keeping IsAutoUpdating
in the model, correct?
I'm seeing this "odd" behavior - where the actual behavior of the button and chart are correct - but the state of IsAutoUpdating is remaining "True" after the control is deactivated. I'm missing something in the logic flow here. Maybe a change is needed to the binding type that I don't quite grok?
This works but I feel like the logic seems "iffy". š š
| AutoUpdate ->
let autoUpdateStatus = not model.IsAutoUpdating
{ model with
IsAutoUpdating = autoUpdateStatus
Actions = model.Actions @ [ { Description = $"Is Auto Updating: {autoUpdateStatus}"; Timestamp = DateTime.Now } ]
}
Am I reading this right that this is actually the DataGrid getting this update "before" the autoUpdateSubscription
is triggered? This likely requires more depth of understanding for AvaloniaProgram.withSubscription
than I have right now. I'm honestly not sure how much order-of-operations matters as the "behavior" seems correct.
I'm in the process of following your suggestion and added "isAutoUpdating" from my earlier PR to a model.IsAutoUpdating bool value. I've done all of the homework down to modifying the logic in the subscription to look at
model.IsAutoUpdating
and while it compiles and runs the chart doesn't update when the AutoUpdate button is triggered. I'm wondering if this is related to the eagerness of F#'s evaluation - and should this take a different form. Thoughts? Thanks!