on develop help sign in
Eliminate all uses of mapDyn
commitbeb263ac2e4c168fb188cde238a2349992c08300 authorRyan Trinkle <ryan.trinkle@gmail.com> dateSun 17 Jul 2016, 11:00 (10 years ago) parent81d62ce
3 files changed+13−44
src/Reflex/Dom/Widget/Basic.hs+4−4 src/Reflex/Dom/Widget/Input.hs+1−32 src/Reflex/Dom/Widget/Lazy.hs+8−8
src/Reflex/Dom/Widget/Basic.hs+4−4
@@ -82,7 +82,7 @@ listHoldWithKey initialChildren modifyChildren buildChild = do
8282 let newInsertedAbove = switch $ mconcat . reverse . fmap (snd . unChildResult) . Map.elems <$> current augmentedResults
8383 belowAll <- placeholder $ def & placeholderConfig_insertAbove .~ fmap (imapM buildAugmentedChild) (select placeChildSelector $ Const2 $ Right ())
8484 let newInsertedBelow = fmap Just <$> _placeholder_insertedAbove belowAll
85− mapDyn (fmap (fst . unChildResult)) augmentedResults
85+ return $ fmap (fmap (fst . unChildResult)) augmentedResults
8686
8787text :: DomBuilder t m => Text -> m ()
8888text t = void $ textNode $ def & textNodeConfig_contents .~ t
@@ -97,7 +97,7 @@ dynText t = do
9797 return ()
9898
9999display :: (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)
101101
102102button :: DomBuilder t m => Text -> m (Event t ())
103103button t = do
@@ -300,7 +300,7 @@ list dm mkChild = listWithKey dm (\_ dv -> mkChild dv)
300300
301301-- | Create a dynamically-changing set of widgets from a Dynamic list.
302302simpleList :: (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
304304
305305{-
306306schedulePostBuild x = performEvent_ . (x <$) =<< getPostBuild
@@ -399,7 +399,7 @@ tabDisplay ulClass activeClass tabItems = do
399399 where
400400 headerBarLink :: Text -> k -> Dynamic t Bool -> m (Event t k)
401401 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
403403 elDynAttr "li" attrs $ do
404404 a <- link x
405405 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
101101 , _textInput_hasFocus = _inputElement_hasFocus i
102102 , _textInput_element = castToHTMLInputElement $ _element_raw $ _inputElement_element i
103103 }
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−-}
124104
125105{-# INLINABLE textInputGetEnter #-}
126106textInputGetEnter :: Reflex t => TextInput t -> Event t ()
@@ -284,17 +264,6 @@ checkboxView dAttrs dValue = do
284264 & inputElementConfig_elementConfig .~ elementConfig
285265 i <- inputElement inputElementConfig
286266 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−-}
298267
299268data FileInput t
300269 = FileInput { _fileInput_value :: Dynamic t [File]
@@ -430,7 +399,7 @@ dropdown k0 options (DropdownConfig setK attrs) = do
430399 Just1 (EventResult r) -> return $ Just1 $ DropdownViewEventResult $ regularToDropdownViewEventType en r
431400 }
432401 (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
434403 elDynAttr "option" optionAttrs $ dynText v
435404 let e = castToHTMLSelectElement $ _element_raw eRaw
436405 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
4040 -> (Int -> k) -- ^ Index to Key function, used to determine position of Map elements
4141 -> 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
4242virtualListWithSelection heightPx rowPx maxIndex i0 setI listTag listAttrs rowTag rowAttrs itemBuilder items indexToKey = do
43− totalHeightStyle <- mapDyn (toHeightStyle . (*) rowPx) maxIndex
44− containerStyle <- mapDyn toContainer heightPx
45− viewportStyle <- mapDyn toViewport heightPx
43+ let totalHeightStyle = fmap (toHeightStyle . (*) rowPx) maxIndex
44+ containerStyle = fmap toContainer heightPx
45+ viewportStyle = fmap toViewport heightPx
4646 rec (container, sel) <- elDynAttr "div" containerStyle $ elDynAttr' "div" viewportStyle $ do
47− currentTop <- mapDyn (listWrapperStyle . fst) window
47+ let currentTop = fmap (listWrapperStyle . fst) window
4848 (_, lis) <- elDynAttr "div" totalHeightStyle $ tagWrapper listTag listAttrs currentTop $ selectViewListWithKey_ selected itemsInWindow $ \k v s -> do
4949 (li,_) <- tagWrapper rowTag rowAttrs (constDyn $ toHeightStyle rowPx) $ itemBuilder k v s
5050 return $ fmap (const k) (domEvent Click li)
@@ -59,7 +59,7 @@ virtualListWithSelection heightPx rowPx maxIndex i0 setI listTag listAttrs rowTa
5959 postBuild <- getPostBuild
6060 performEvent_ $ ffor (leftmost [setI, i0 <$ postBuild]) $ \i -> do
6161 liftIO $ setScrollTop (_element_raw container) (i * rowPx)
62− indexAndLength <- mapDyn snd window
62+ let indexAndLength = fmap snd window
6363 return (indexAndLength, sel)
6464 where
6565 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,
9191 -> (k -> v -> Event t v -> m a) -- ^ The row child element builder.
9292 -> 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
9393virtualList heightPx rowPx maxIndex i0 setI keyToIndex items0 itemsUpdate itemBuilder = do
94− virtualH <- mapDyn (mkVirtualHeight . (*) rowPx) maxIndex
95− containerStyle <- mapDyn mkContainer heightPx
96− viewportStyle <- mapDyn mkViewport heightPx
94+ let virtualH = fmap (mkVirtualHeight . (*) rowPx) maxIndex
95+ containerStyle = fmap mkContainer heightPx
96+ viewportStyle = fmap mkViewport heightPx
9797 pb <- getPostBuild
9898 rec (viewport, result) <- elDynAttr "div" containerStyle $ elDynAttr' "div" viewportStyle $ elDynAttr "div" virtualH $
9999 listWithKeyShallowDiff items0 itemsUpdate $ \k v e -> elAttr "div" (mkRow k) $ itemBuilder k v e