Comments (6)
You are not missing anything. When writing this library, XAML prevailed as the best way to write WPF views (see #1). The view bindings are one extra step required to bind the view to the model.
let view _ _ = ...
should really be let bindings _ _ = ...
, and I have been writing it that way for a while. I'll update the samples and docs to reflect this, hopefully it will make things more clear.
from elmish.wpf.
It's worth mentioning that we've been talking about something on top of XAML (which relies on mutations heavily), something that would provide immutable model and work similar to what React/VirtualDOM is doing. There's prior art in Kotlin ecosystem that does this for Android forms, using codegen to create an immutable diffable model based on the forms types. Maybe we could do something similar with F# type providers, and define the diffable model by pointing the TP at a XAML library that contains the UI elements.
from elmish.wpf.
Would this still use WPF bindings under the hood or some other mechanism? What you describe sounds ideal, but how would it be possible to abstract something like Grid
vs DockPanel
? Or would the diffable model just contain a limited subset of controls?
from elmish.wpf.
Shouldn't it be possible to make the view return xaml UI element and corresponding binding ?
Mvu elements could then control the way UI elements are composed and how they are rendered dynamically (with bindings).
Main advantages I see :
- parent-child composition is now allowed
- no more dependencies between xaml files
from elmish.wpf.
It is possible, but would also require significant development effort to achieve. There are some downsides, too, such as designers losing the ability to use tools like Blend for developers to create implementations for those views.
Either way, for this library at least and for now, creating views in xaml and writing elmish logic flow seems like a "good enough" balance.
Just FYI in case you haven't seen it, there is at least one example of an attempt to implement what you describe.
from elmish.wpf.
I've been thinking on this topic while working on my Elmish.WPF rewrite/extension (#46).
A core tenet of Elm's guidelines seems to be keeping models and messages shallow, opting for reusable views instead of reusable components. This, as far as I have thought about it, is simply not possible in Elmish.WPF exactly because the "view" function doesn't create views, but bindings. The views have to be pre-defined (using XAML) and can't be generated by a pure function. (What the OP said, in other words.)
We are thus left with creating reusable components. For a while, we may be able to stick to a single ever-growing model / message type / update function (with one crucial exception mentioned below), but as the app grows more complex, the way to divide and conquer in Elmish.WPF must necessarily be to factor out functionality to sub-models, with their own message types and update functions.
Unless I've overlooked a possibility (which I may very well have), sub-components is however a strict requirement when using any kind of ItemsControl
where elements contain e.g. a TextBox
. While it's possible for Button
s to bind CommandParameter
to some unique identifier for a particular element, and thus for the update function to know which item's button was clicked, TextBox
does not support such a feature. The only way to know which ItemsControl
item the message originated from in this case is to have each item be its own component (with its own model, message type, and update function).
This is enabled by the changes discussed in #46 (Binding.modelSeq
), so at least it's possible, but there are downsides of using components that are not fully orthogonal. As discussed in the Hacker Noon article The importance of state ownership in Elm, sub-components may depend on state from their parents (for example, in my accounting app, more or less all components depend in some manner on the list of transactions and categories). Like the author of that article, I can see no optimal solutions to giving child components access to (part of) their parent's state that does not open up for state duplication and/or forgetting to update child models when the relevant parent state changes.
Just some thoughts here, no real conclusions.
from elmish.wpf.
Related Issues (20)
- v4. Runtime Exception after upgrading from v3. HOT 5
- Update is performed two times while closing an window HOT 3
- Visibility binding doesn't work in some samples HOT 3
- Combining Sub-model window and Sub-model sequence HOT 7
- Weird binding behaviour HOT 5
- Support for Maps of dynamic bindings HOT 8
- How to switch between 2 user controls in 1 space HOT 2
- Elmish.Avalonia HOT 2
- subModelWin issue passing a parameter HOT 11
- Binding.TwoWay setter with parameters given from xaml HOT 6
- Why use data typed tuple compared to struct tuples? HOT 1
- Documentation doesn't specify how to define Program.main using typed view model classes HOT 3
- How to send a message to the Dispatcher from a custom event? HOT 2
- Feature request: View model member exposed as Action<T> HOT 2
- How to enable the user to find a TreeViewItem HOT 29
- How to update binding after validation HOT 4
- (resolved-delete)
- 3rd-party custom Window : Building fine but not showing at runtime HOT 8
- Best way to implement "Statically-typed view model" approach? HOT 5
- Drop targeting of .NET Core 3.1? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elmish.wpf.