Skip to content

Commit 04c74fb

Browse files
author
Tyson Williams
committed
changed update to use "explicit model" style
1 parent a793d73 commit 04c74fb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Samples/SubModelSeq/Program.fs

+8-7
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ module App =
169169
|> Func.dedup
170170
|> RoseTree.mapChildren
171171

172-
let update = function
173-
| ToggleGlobalState -> not |> SomeGlobalState.map
174-
| CounterMsg (nId, msg) -> msg |> Counter.update |> Identifiable.mapIfId nId |> RoseTree.mapData |> DummyRoot.map
175-
| AddCounter pId -> () |> Guid.NewGuid |> addChildCounter |> mapIf (hasId pId) |> RoseTree.map |> DummyRoot.map
176-
| Remove nId -> nId |> hasId >> not |> List.filter |> RoseTree.mapChildren |> RoseTree.map |> DummyRoot.map
177-
| MoveUp nId -> nId |> swapCounters List.swapWithPrev |> RoseTree.map |> DummyRoot.map
178-
| MoveDown nId -> nId |> swapCounters List.swapWithNext |> RoseTree.map |> DummyRoot.map
172+
let update msg m =
173+
match msg with
174+
| ToggleGlobalState -> { m with SomeGlobalState = not m.SomeGlobalState }
175+
| CounterMsg (nId, msg) -> { m with DummyRoot = (msg |> Counter.update |> Identifiable.mapIfId nId |> RoseTree.mapData) m.DummyRoot }
176+
| AddCounter pId -> { m with DummyRoot = (Guid.NewGuid () |> addChildCounter |> mapIf (hasId pId) |> RoseTree.map) m.DummyRoot }
177+
| Remove nId -> { m with DummyRoot = (nId |> hasId >> not |> List.filter |> RoseTree.mapChildren |> RoseTree.map) m.DummyRoot }
178+
| MoveUp nId -> { m with DummyRoot = (nId |> swapCounters List.swapWithPrev |> RoseTree.map) m.DummyRoot }
179+
| MoveDown nId -> { m with DummyRoot = (nId |> swapCounters List.swapWithNext |> RoseTree.map) m.DummyRoot }
179180

180181
/// Returns all top-level counters.
181182
let topLevelCounters m =

0 commit comments

Comments
 (0)