File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,46 @@ The Reflex library was built for Haskell web development via ghcjs. It features
60
60
* compare ToDoMVC to Elm
61
61
* what does foldDyn do and what's its type ? Show how the stream is higher order.
62
62
63
+ ```haskell
64
+ todoMVC :: ( DomBuilder t m
65
+ , DomBuilderSpace m ~ GhcjsDomSpace
66
+ , MonadFix m
67
+ , MonadHold t m
68
+ , PostBuild t m
69
+ )
70
+ => m ()
71
+ todoMVC = do
72
+ el " div" $ do
73
+ elAttr " section" (" class" =: " todoapp" ) $ do
74
+ mainHeader
75
+
76
+ foldDyn :: (a -> b -> b ) -> b -> Event a -> m (Dynamic b )
77
+ tasks :: Dynamic (Map Int Task )
78
+ rec tasks <- foldDyn (\ transformation oldTasks -> transformation oldTasks) initialTasks listTransformationEvent
79
+
80
+ mergeWith :: (a -> a -> a ) -> [Event a ] -> Event a
81
+ listTransformationEvent :: Event (Map Int Task -> Map Int Task )
82
+ let listTransformationEvent = mergeWith (.) [
83
+ insertNewEvent
84
+ , listModifyTasks
85
+ , clearCompletedEvent
86
+ ]
87
+
88
+ let insertNewEvent :: Event (Map Int Task -> Map Int Task )
89
+ insertNewEvent = fmap insertNew_ newTask
90
+ newTask <- taskEntry
91
+
92
+ listModifyTasks :: Event (Map Int Task -> Map Int Task )
93
+ listModifyTasks <- taskList activeFilter tasks
94
+
95
+ (activeFilter, clearCompleted) <- controls tasks
96
+ fmap :: (a -> b ) -> Dynamic a -> Dynamic b
97
+ let clearCompletedEvent :: Event (Map Int Task -> Map Int Task )
98
+ clearCompletedEvent = fmap (\ _ -> Map. filter $ not . taskCompleted) clearCompleted
99
+ return ()
100
+ infoFooter
101
+ ```
102
+
63
103
## 4. Is the cure worse than the disease?
64
104
65
105
* how the elm architecure is good
You can’t perform that action at this time.
0 commit comments