窗口上有几个按钮,我试图找到处理命令的好方法。
例如:
我得做些动作:
type Action =
|Show
|Open
|Input
|Change
|Statistic将此转换为xaml将是:
<Button Command="{Binding ShowCommand}" />
<Button Command="{Binding OpenCommand}" />
<Button Command="{Binding InputCommand}" />
<Button Command="{Binding ChangeCommand}" />
<Button Command="{Binding StatisticCommand}" />稍微玩一下库,我找到了两种不用烦人的冗长的方法。
Binding.createMessage "StatisticCommand" Statistic source
|> Observable.merge (Binding.createMessage "InputCommand" Input source)
//|> Observable.merge ... and so on
|> Observable.subscribe (performAction model.Value)
|> source.AddDisposabletype GeneralMessage =
|Perform of Action
|Update of Message并将行动信息提升到高层
let mainComponent source (model : ISignal<Info>) =
let info = Binding.componentToView source "Info" infoComponent model
//...
let stat = Binding.createMessage "StatCommand" (Perform Statistic) source
let input = Binding.createMessage "InputCommand" (Perform Input) source
//let ...
[info; stat; input; ...]
let appComponent =
let model = initInfo
let update message model =
match message with
|Update message ->
match message with
|...
|Perform action ->
performAction model action
model
Framework.basicApplication model update mainComponent(嗯,我喜欢第一种选择,因为这个动作不会改变模型)
是做这些事情的正确方式(第一种,显而易见的),还是库中包含更合适的功能?
我在找Observable.concat [info; stat; input; ...],但运气不好。
发布于 2017-08-07 20:38:12
所以这两种选择都可以。我认为适当的方法取决于如何使用,以及需要什么数据:
https://stackoverflow.com/questions/45553650
复制相似问题