fsprojects / Avalonia.FuncUI

Develop cross-plattform GUI Applications using F# and Avalonia!
https://funcui.avaloniaui.net/
MIT License
887 stars 72 forks source link

Consider allowing adaptive views as an option #20

Open dsyme opened 4 years ago

dsyme commented 4 years ago

This is about potentially allowing the use of adaptive view specifications, see https://github.com/fsprojects/FSharp.Data.Adaptive

From https://github.com/fsprojects/Fabulous/issues/258#issuecomment-537933705

@JaggerJo The FuncUI implementation is really good - this file is impressive https://github.com/dsyme/Avalonia.FuncUI/blob/master/src/Avalonia.FuncUI/Core/VirtualDom.fs

That said, it's still using view-reevaluation - for example if there are 10K data points in a chart and one is removed then the view is re-evaluated and, in the absence of other hacks, this will involve a significant amount of work to spot the minimal diff.

FuncUI can, I think, be adapted to work with adaptive data relatively easily. This would mean that the 'view' functions are not re-executed on update (except where necessary for incremental DOM maintenance). The diffs in the view would flow out of the adaptive data, rather than having to diff an old and new view like you do here

There's a sample showing how to define a tree of adaptive view-like data and perform incremental maintenance on a mutable HTMLElement data strucutre here: https://github.com/dsyme/FSharp.Data.Adaptive/blob/dom-node/src/FSharp.Data.Adaptive.Tests/DomUpdater.fs. The variation FuncUI would need would be a bit different - for example FuncUI could define a ViewReader for the AdaptiveView type, producing a ViewDelta (and then patch is called on that).

Swoorup commented 4 years ago

Does this mean that on a particular adaptive changes, you could avoid virtual diffing for that component, and just directly update that particular element using that adaptive variable?

JaggerJo commented 4 years ago

@Swoorup Yes, exactly.

The hard thing is building a DSL that works well with the MVU architecture IMHO.

Im following @krauthaufen's progress here https://github.com/krauthaufen/Fable.Elmish.Adaptive

Swoorup commented 4 years ago

Cool, sounds really useful for building realtime charts/graph which might have lot of data points.