@@ -89,6 +89,15 @@ module CounterTypes =
89
89
| SetStepSize x -> { m with StepSize = x }
90
90
| Reset -> init
91
91
92
+ let bindings () : Binding < Counter , CounterMsg > list = [
93
+ " CounterValue" |> Binding.oneWay ( fun m -> m.Count)
94
+ " Increment" |> Binding.cmd Increment
95
+ " Decrement" |> Binding.cmd Decrement
96
+ " StepSize" |> Binding.twoWay(
97
+ ( fun m -> float m.StepSize),
98
+ int >> SetStepSize)
99
+ " Reset" |> Binding.cmdIf( Reset, canReset)
100
+ ]
92
101
93
102
94
103
[<AutoOpen>]
@@ -212,40 +221,39 @@ module Bindings =
212
221
213
222
open App
214
223
215
- let rec counterTreeBindings () : Binding < Model * Identifiable < Counter >, Msg > list = [
216
- " CounterIdText" |> Binding.oneWay( fun ( _ , c ) -> c.Id)
217
-
218
- " CounterValue" |> Binding.oneWay( fun ( _ , c ) -> c.Value.Count)
219
- " Increment" |> Binding.cmd( fun ( _ , c ) -> CounterMsg ( c.Id, Increment))
220
- " Decrement" |> Binding.cmd( fun ( _ , c ) -> CounterMsg ( c.Id, Decrement))
221
- " StepSize" |> Binding.twoWay(
222
- ( fun ( _ , c ) -> float c.Value.StepSize),
223
- ( fun v ( _ , c ) -> CounterMsg ( c.Id, SetStepSize ( int v))))
224
- " Reset" |> Binding.cmdIf(
225
- ( fun ( _ , c ) -> CounterMsg ( c.Id, Reset)),
226
- ( fun ( _ , c ) -> Counter.canReset c.Value))
227
-
228
- " Remove" |> Binding.cmd( fun ( _ , c ) -> Remove c.Id)
229
-
230
- " AddChild" |> Binding.cmd( fun ( _ , c ) -> AddCounter c.Id)
231
-
232
- " MoveUp" |> Binding.cmdIf(
233
- ( fun ( _ , c ) -> MoveUp c.Id),
234
- ( fun ( m , c ) -> m |> childrenCountersOfParentOf c.Id |> List.tryHead <> Some c))
235
-
236
- " MoveDown" |> Binding.cmdIf(
237
- ( fun ( _ , c ) -> MoveDown c.Id),
238
- ( fun ( m , c ) -> m |> childrenCountersOfParentOf c.Id |> List.tryLast <> Some c))
239
-
240
- " GlobalState" |> Binding.oneWay( fun ( m , _ ) -> m.SomeGlobalState)
241
-
242
- " ChildCounters" |> Binding.subModelSeq(
243
- ( fun ( m , c ) -> m |> childrenCountersOf c.Id),
244
- ( fun (( m , _ ), childCounter ) -> ( m, childCounter)),
245
- ( fun ( _ , c ) -> c.Id),
246
- snd,
247
- counterTreeBindings)
248
- ]
224
+ let rec counterTreeBindings () : Binding < Model * Identifiable < Counter >, Msg > list =
225
+ let counterBindings =
226
+ Counter.bindings ()
227
+ |> Bindings.mapModel ( fun ( _ , c ) -> c.Value)
228
+ |> Bindings.mapMsgWithModel ( fun ( _ , c ) msg -> CounterMsg ( c.Id, msg))
229
+ let newBindings =
230
+ [
231
+ " CounterIdText" |> Binding.oneWay( fun ( _ , c ) -> c.Id)
232
+
233
+ " Remove" |> Binding.cmd( fun ( _ , c ) -> Remove c.Id)
234
+
235
+ " AddChild" |> Binding.cmd( fun ( _ , c ) -> AddCounter c.Id)
236
+
237
+ " MoveUp" |> Binding.cmdIf(
238
+ ( fun ( _ , c ) -> MoveUp c.Id),
239
+ ( fun ( m , c ) -> m |> childrenCountersOfParentOf c.Id |> List.tryHead <> Some c))
240
+
241
+ " MoveDown" |> Binding.cmdIf(
242
+ ( fun ( _ , c ) -> MoveDown c.Id),
243
+ ( fun ( m , c ) -> m |> childrenCountersOfParentOf c.Id |> List.tryLast <> Some c))
244
+
245
+ " GlobalState" |> Binding.oneWay( fun ( m , _ ) -> m.SomeGlobalState)
246
+
247
+ " ChildCounters" |> Binding.subModelSeq(
248
+ ( fun ( m , c ) -> m |> childrenCountersOf c.Id),
249
+ ( fun (( m , _ ), childCounter ) -> ( m, childCounter)),
250
+ ( fun ( _ , c ) -> c.Id),
251
+ snd,
252
+ counterTreeBindings)
253
+ ]
254
+ [ counterBindings
255
+ newBindings ]
256
+ |> List.concat
249
257
250
258
251
259
let rootBindings () : Binding < Model , Msg > list = [
0 commit comments