on develop help sign in
Eliminate all uses of mapDyn
beb263aRyan Trinkle
src/Reflex/Dom/Widget/Basic.hs+4−4
@@ -82,7 +82,7 @@ listHoldWithKey initialChildren modifyChildren buildChild = do
82 let newInsertedAbove = switch $ mconcat . reverse . fmap (snd . unChildResult) . Map.elems <$> current augmentedResults
82 let newInsertedAbove = switch $ mconcat . reverse . fmap (snd . unChildResult) . Map.elems <$> current augmentedResults
83 belowAll <- placeholder $ def & placeholderConfig_insertAbove .~ fmap (imapM buildAugmentedChild) (select placeChildSelector $ Const2 $ Right ())
83 belowAll <- placeholder $ def & placeholderConfig_insertAbove .~ fmap (imapM buildAugmentedChild) (select placeChildSelector $ Const2 $ Right ())
84 let newInsertedBelow = fmap Just <$> _placeholder_insertedAbove belowAll
84 let newInsertedBelow = fmap Just <$> _placeholder_insertedAbove belowAll
85− mapDyn (fmap (fst . unChildResult)) augmentedResults
85+ return $ fmap (fmap (fst . unChildResult)) augmentedResults
86
86
87text :: DomBuilder t m => Text -> m ()
87text :: DomBuilder t m => Text -> m ()
88text t = void $ textNode $ def & textNodeConfig_contents .~ t
88text t = void $ textNode $ def & textNodeConfig_contents .~ t
@@ -97,7 +97,7 @@ dynText t = do
97 return ()
97 return ()
98
98
99display :: (PostBuild t m, DomBuilder t m, Show a) => Dynamic t a -> m ()
99display :: (PostBuild t m, DomBuilder t m, Show a) => Dynamic t a -> m ()
100−display = dynText <=< mapDyn (T.pack . show)
100+display = dynText . fmap (T.pack . show)
101
101
102button :: DomBuilder t m => Text -> m (Event t ())
102button :: DomBuilder t m => Text -> m (Event t ())
103button t = do
103button t = do
@@ -300,7 +300,7 @@ list dm mkChild = listWithKey dm (\_ dv -> mkChild dv)
300
300
301-- | Create a dynamically-changing set of widgets from a Dynamic list.
301-- | Create a dynamically-changing set of widgets from a Dynamic list.
302simpleList :: (DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m) => Dynamic t [v] -> (Dynamic t v -> m a) -> m (Dynamic t [a])
302simpleList :: (DomBuilder t m, MonadHold t m, PostBuild t m, MonadFix m) => Dynamic t [v] -> (Dynamic t v -> m a) -> m (Dynamic t [a])
303−simpleList xs mkChild = mapDyn (map snd . Map.toList) =<< flip list mkChild =<< mapDyn (Map.fromList . zip [(1::Int)..]) xs
303+simpleList xs mkChild = fmap (fmap (map snd . Map.toList)) $ flip list mkChild $ fmap (Map.fromList . zip [(1::Int)..]) xs
304
304
305{-
305{-
306schedulePostBuild x = performEvent_ . (x <$) =<< getPostBuild
306schedulePostBuild x = performEvent_ . (x <$) =<< getPostBuild
@@ -399,7 +399,7 @@ tabDisplay ulClass activeClass tabItems = do
399 where
399 where
400 headerBarLink :: Text -> k -> Dynamic t Bool -> m (Event t k)
400 headerBarLink :: Text -> k -> Dynamic t Bool -> m (Event t k)
401 headerBarLink x k isSelected = do
401 headerBarLink x k isSelected = do
402− attrs <- mapDyn (\b -> if b then Map.singleton "class" activeClass else Map.empty) isSelected
402+ let attrs = fmap (\b -> if b then Map.singleton "class" activeClass else Map.empty) isSelected
403 elDynAttr "li" attrs $ do
403 elDynAttr "li" attrs $ do
404 a <- link x
404 a <- link x
405 return $ fmap (const k) (_link_clicked a)
405 return $ fmap (const k) (_link_clicked a)
src/Reflex/Dom/Widget/Input.hs+1−32
@@ -101,26 +101,6 @@ textInput (TextInputConfig inputType initial eSetValue dAttrs) = do
101 , _textInput_hasFocus = _inputElement_hasFocus i
101 , _textInput_hasFocus = _inputElement_hasFocus i
102 , _textInput_element = castToHTMLInputElement $ _element_raw $ _inputElement_element i
102 , _textInput_element = castToHTMLInputElement $ _element_raw $ _inputElement_element i
103 }
103 }
104−{-
105− e <- liftM castToHTMLInputElement $ buildEmptyElement "input" =<< mapDyn (Map.insert "type" inputType) dAttrs
106− Input.setValue e $ Just initial
107− performEvent_ $ fmap (Input.setValue e . Just) eSetValue
108− eChange <- wrapDomEvent e (`on` input) $ fromMaybe "" <$> Input.getValue e
109− postGui <- askPostGui
110− runWithActions <- askRunWithActions
111− eChangeFocus <- newEventWithTrigger $ \eChangeFocusTrigger -> do
112− unsubscribeOnblur <- on e blurEvent $ liftIO $ do
113− postGui $ runWithActions [eChangeFocusTrigger :=> Identity False]
114− unsubscribeOnfocus <- on e focusEvent $ liftIO $ do
115− postGui $ runWithActions [eChangeFocusTrigger :=> Identity True]
116− return $ liftIO $ unsubscribeOnblur >> unsubscribeOnfocus
117− dFocus <- holdDyn False eChangeFocus
118− eKeypress <- wrapDomEvent e (`on` keyPress) getKeyEvent
119− eKeydown <- wrapDomEvent e (`on` keyDown) getKeyEvent
120− eKeyup <- wrapDomEvent e (`on` keyUp) getKeyEvent
121− dValue <- holdDyn initial $ leftmost [eSetValue, eChange]
122− return $ TextInput dValue eChange eKeypress eKeydown eKeyup dFocus e
123−-}
124
104
125{-# INLINABLE textInputGetEnter #-}
105{-# INLINABLE textInputGetEnter #-}
126textInputGetEnter :: Reflex t => TextInput t -> Event t ()
106textInputGetEnter :: Reflex t => TextInput t -> Event t ()
@@ -284,17 +264,6 @@ checkboxView dAttrs dValue = do
284 & inputElementConfig_elementConfig .~ elementConfig
264 & inputElementConfig_elementConfig .~ elementConfig
285 i <- inputElement inputElementConfig
265 i <- inputElement inputElementConfig
286 return $ unCheckboxViewEventResult <$> select (_element_events $ _inputElement_element i) (WrapArg Click)
266 return $ unCheckboxViewEventResult <$> select (_element_events $ _inputElement_element i) (WrapArg Click)
287−{-
288− e <- liftM castToHTMLInputElement $ buildEmptyElement "input" =<< mapDyn (Map.insert "type" "checkbox") dAttrs
289− eClicked <- wrapDomEvent e (`on` click) $ do
290− preventDefault
291− Input.getChecked e
292− schedulePostBuild $ do
293− v <- sample $ current dValue
294− when v $ Input.setChecked e True
295− performEvent_ $ fmap (\v -> Input.setChecked e $! v) $ updated dValue
296− return eClicked
297−-}
298
267
299data FileInput t
268data FileInput t
300 = FileInput { _fileInput_value :: Dynamic t [File]
269 = FileInput { _fileInput_value :: Dynamic t [File]
@@ -430,7 +399,7 @@ dropdown k0 options (DropdownConfig setK attrs) = do
430 Just1 (EventResult r) -> return $ Just1 $ DropdownViewEventResult $ regularToDropdownViewEventType en r
399 Just1 (EventResult r) -> return $ Just1 $ DropdownViewEventResult $ regularToDropdownViewEventType en r
431 }
400 }
432 (eRaw, _) <- element "select" cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
401 (eRaw, _) <- element "select" cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
433− optionAttrs <- mapDyn (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
402+ let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
434 elDynAttr "option" optionAttrs $ dynText v
403 elDynAttr "option" optionAttrs $ dynText v
435 let e = castToHTMLSelectElement $ _element_raw eRaw
404 let e = castToHTMLSelectElement $ _element_raw eRaw
436 performEvent_ $ HTMLSelectElement.setValue e . Just . show <$> attachDynWithMaybe (flip Bimap.lookupR) ixKeys setK
405 performEvent_ $ HTMLSelectElement.setValue e . Just . show <$> attachDynWithMaybe (flip Bimap.lookupR) ixKeys setK
src/Reflex/Dom/Widget/Lazy.hs+8−8
@@ -40,11 +40,11 @@ virtualListWithSelection :: forall t m k v. (DomBuilder t m, PostBuild t m, Mona
40 -> (Int -> k) -- ^ Index to Key function, used to determine position of Map elements
40 -> (Int -> k) -- ^ Index to Key function, used to determine position of Map elements
41 -> m (Dynamic t (Int, Int), Event t k) -- ^ A tuple containing: a 'Dynamic' of the index (based on the current scroll position) and number of items currently being rendered, and an 'Event' of the selected key
41 -> m (Dynamic t (Int, Int), Event t k) -- ^ A tuple containing: a 'Dynamic' of the index (based on the current scroll position) and number of items currently being rendered, and an 'Event' of the selected key
42virtualListWithSelection heightPx rowPx maxIndex i0 setI listTag listAttrs rowTag rowAttrs itemBuilder items indexToKey = do
42virtualListWithSelection heightPx rowPx maxIndex i0 setI listTag listAttrs rowTag rowAttrs itemBuilder items indexToKey = do
43− totalHeightStyle <- mapDyn (toHeightStyle . (*) rowPx) maxIndex
43+ let totalHeightStyle = fmap (toHeightStyle . (*) rowPx) maxIndex
44− containerStyle <- mapDyn toContainer heightPx
44+ containerStyle = fmap toContainer heightPx
45− viewportStyle <- mapDyn toViewport heightPx
45+ viewportStyle = fmap toViewport heightPx
46 rec (container, sel) <- elDynAttr "div" containerStyle $ elDynAttr' "div" viewportStyle $ do
46 rec (container, sel) <- elDynAttr "div" containerStyle $ elDynAttr' "div" viewportStyle $ do
47− currentTop <- mapDyn (listWrapperStyle . fst) window
47+ let currentTop = fmap (listWrapperStyle . fst) window
48 (_, lis) <- elDynAttr "div" totalHeightStyle $ tagWrapper listTag listAttrs currentTop $ selectViewListWithKey_ selected itemsInWindow $ \k v s -> do
48 (_, lis) <- elDynAttr "div" totalHeightStyle $ tagWrapper listTag listAttrs currentTop $ selectViewListWithKey_ selected itemsInWindow $ \k v s -> do
49 (li,_) <- tagWrapper rowTag rowAttrs (constDyn $ toHeightStyle rowPx) $ itemBuilder k v s
49 (li,_) <- tagWrapper rowTag rowAttrs (constDyn $ toHeightStyle rowPx) $ itemBuilder k v s
50 return $ fmap (const k) (domEvent Click li)
50 return $ fmap (const k) (domEvent Click li)
@@ -59,7 +59,7 @@ virtualListWithSelection heightPx rowPx maxIndex i0 setI listTag listAttrs rowTa
59 postBuild <- getPostBuild
59 postBuild <- getPostBuild
60 performEvent_ $ ffor (leftmost [setI, i0 <$ postBuild]) $ \i -> do
60 performEvent_ $ ffor (leftmost [setI, i0 <$ postBuild]) $ \i -> do
61 liftIO $ setScrollTop (_element_raw container) (i * rowPx)
61 liftIO $ setScrollTop (_element_raw container) (i * rowPx)
62− indexAndLength <- mapDyn snd window
62+ let indexAndLength = fmap snd window
63 return (indexAndLength, sel)
63 return (indexAndLength, sel)
64 where
64 where
65 toStyleAttr m = "style" =: Map.foldWithKey (\k v s -> k <> ":" <> v <> ";" <> s) "" m
65 toStyleAttr m = "style" =: Map.foldWithKey (\k v s -> k <> ":" <> v <> ";" <> s) "" m
@@ -91,9 +91,9 @@ virtualList :: forall t m k v a. (DomBuilder t m, PostBuild t m, MonadHold t m,
91 -> (k -> v -> Event t v -> m a) -- ^ The row child element builder.
91 -> (k -> v -> Event t v -> m a) -- ^ The row child element builder.
92 -> m (Dynamic t (Int, Int), Dynamic t (Map k a)) -- ^ A tuple containing: a 'Dynamic' of the index (based on the current scroll position) and number of items currently being rendered, and the 'Dynamic' list result
92 -> m (Dynamic t (Int, Int), Dynamic t (Map k a)) -- ^ A tuple containing: a 'Dynamic' of the index (based on the current scroll position) and number of items currently being rendered, and the 'Dynamic' list result
93virtualList heightPx rowPx maxIndex i0 setI keyToIndex items0 itemsUpdate itemBuilder = do
93virtualList heightPx rowPx maxIndex i0 setI keyToIndex items0 itemsUpdate itemBuilder = do
94− virtualH <- mapDyn (mkVirtualHeight . (*) rowPx) maxIndex
94+ let virtualH = fmap (mkVirtualHeight . (*) rowPx) maxIndex
95− containerStyle <- mapDyn mkContainer heightPx
95+ containerStyle = fmap mkContainer heightPx
96− viewportStyle <- mapDyn mkViewport heightPx
96+ viewportStyle = fmap mkViewport heightPx
97 pb <- getPostBuild
97 pb <- getPostBuild
98 rec (viewport, result) <- elDynAttr "div" containerStyle $ elDynAttr' "div" viewportStyle $ elDynAttr "div" virtualH $
98 rec (viewport, result) <- elDynAttr "div" containerStyle $ elDynAttr' "div" viewportStyle $ elDynAttr "div" virtualH $
99 listWithKeyShallowDiff items0 itemsUpdate $ \k v e -> elAttr "div" (mkRow k) $ itemBuilder k v e
99 listWithKeyShallowDiff items0 itemsUpdate $ \k v e -> elAttr "div" (mkRow k) $ itemBuilder k v e