on develop help sign in
General cleanup
commitb10f2ade1affcb76452bef73c93cf4c4c4f5900c authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 24 Mar 2015, 14:43 (12 years ago) parentc30e6fb
5 files changed+54−98
src/Reflex/Dom/Class.hs+3−21 src/Reflex/Dom/Internal.hs+14−34 src/Reflex/Dom/Widget/Basic.hs+30−31 src/Reflex/Dom/Widget/Input.hs+2−5 src/Reflex/Dom/Xhr.hs+5−7
src/Reflex/Dom/Class.hs+3−21
@@ -7,34 +7,14 @@ import Reflex
77import Reflex.Host.Class
88
99import Control.Monad.Identity hiding (mapM, mapM_, forM, forM_, sequence)
10−import Control.Lens hiding ((<|))
11−import Data.Set (Set)
12−import qualified Data.Set as Set
1310import Data.Map (Map)
1411import qualified Data.Map as Map
15−import Data.Traversable
1612import Data.Foldable
1713import Control.Monad.Ref
1814import Control.Monad.Reader hiding (mapM, mapM_, forM, forM_, sequence)
1915import Control.Monad.State hiding (mapM, mapM_, forM, forM_, sequence)
20−import qualified Data.Dependent.Map as DMap
2116import Data.Dependent.Sum (DSum (..))
22−import Data.IORef
23−import Data.These
24−import Data.Align
2517import GHCJS.DOM.Types hiding (Event)
26−import GHCJS.DOM.Document
27−import GHCJS.DOM.Node
28−import GHCJS.DOM.NamedNodeMap
29−import GHCJS.DOM.Element
30−import GHCJS.DOM.HTMLElement
31−import GHCJS.DOM.HTMLInputElement
32−import GHCJS.DOM.HTMLSelectElement
33−import GHCJS.DOM.HTMLTextAreaElement
34−import GHCJS.DOM.UIEvent
35−import GHCJS.DOM.EventM (event, preventDefault)
36−import Data.Dependent.Map (DMap)
37−import Safe
3818
3919-- | Alias for Data.Map.singleton
4020(=:) :: k -> a -> Map k a
@@ -48,7 +28,7 @@ keycodeEscape = 27
4828
4929class ( Reflex t, MonadHold t m, MonadIO m, Functor m, MonadReflexCreateTrigger t m
5030 , HasDocument m
51− , MonadIO (WidgetHost m), Functor (WidgetHost m), MonadSample t (WidgetHost m)
31+ , MonadIO (WidgetHost m), MonadIO (GuiAction m), Functor (WidgetHost m), MonadSample t (WidgetHost m)
5232 , HasPostGui t (GuiAction m) (WidgetHost m), HasPostGui t (GuiAction m) m, MonadRef m, MonadRef (WidgetHost m)
5333 , Ref m ~ Ref IO, Ref (WidgetHost m) ~ Ref IO --TODO: Eliminate this reliance on IO
5434 , MonadFix m
@@ -106,8 +86,10 @@ instance MonadWidget t m => MonadWidget t (ReaderT r m) where
10686 (a, postBuild, voidActions) <- runWidget rootElement $ runReaderT w r
10787 return (a, postBuild, voidActions)
10888
89+performEvent_ :: MonadWidget t m => Event t (WidgetHost m ()) -> m ()
10990performEvent_ = addVoidAction
11091
92+performEvent :: (MonadWidget t m, Ref m ~ Ref IO) => Event t (WidgetHost m a) -> m (Event t a)
11193performEvent e = do
11294 (eResult, reResultTrigger) <- newEventWithTriggerRef
11395 addVoidAction $ ffor e $ \o -> do
src/Reflex/Dom/Internal.hs+14−34
@@ -8,44 +8,25 @@ import Reflex.Dom.Class
88import GHCJS.DOM
99import GHCJS.DOM.Types hiding (Widget, unWidget, Event)
1010import GHCJS.DOM.Node
11−import GHCJS.DOM.Element
1211import GHCJS.DOM.HTMLElement
13−import GHCJS.DOM.HTMLInputElement
14−import GHCJS.DOM.NamedNodeMap
1512import GHCJS.DOM.Document
16−import GHCJS.DOM.UIEvent
17−import GHCJS.DOM.EventM (event, Signal (..))
1813import Reflex.Class
19−import Reflex.Dynamic
2014import Reflex.Host.Class
2115import Reflex.Spider (Spider, SpiderHost (..))
22−import qualified Reflex.Spider
2316import Control.Lens
24−import Control.Applicative
2517import Control.Monad hiding (mapM, mapM_, forM, forM_, sequence, sequence_)
2618import Control.Monad.Reader hiding (mapM, mapM_, forM, forM_, sequence, sequence_)
2719import Control.Monad.Ref
2820import Control.Monad.State.Strict hiding (mapM, mapM_, forM, forM_, sequence, sequence_)
29−import Data.Map (Map)
30−import qualified Data.Map as Map
31−import Data.Set (Set)
32−import qualified Data.Set as Set
3321import Control.Concurrent
22+import Data.ByteString (ByteString)
3423import Data.Dependent.Sum (DSum (..))
35−import Data.Dependent.Map (DMap)
36−import qualified Data.Dependent.Map as DMap
3724import Data.Foldable
3825import Data.Traversable
39−import Data.IORef
40−import Data.Align
41−import Data.These
42−import Data.ByteString (ByteString)
4326import qualified Data.Text as T
4427import Data.Text.Encoding
4528import Data.Monoid ((<>))
4629
47−import System.IO.Unsafe
48−
4930data GuiEnv t h
5031 = GuiEnv { _guiEnvDocument :: !HTMLDocument
5132 , _guiEnvPostGui :: !(h () -> IO ())
@@ -134,7 +115,7 @@ instance MonadReflexCreateTrigger t m => MonadReflexCreateTrigger t (Widget t m)
134115 newEventWithTrigger = lift . newEventWithTrigger
135116
136117instance ( MonadRef m, Ref m ~ Ref IO, MonadRef h, Ref h ~ Ref IO --TODO: Shouldn't need to be IO
137− , MonadIO m, Functor m
118+ , MonadIO m, MonadIO h, Functor m
138119 , ReflexHost t, MonadReflexCreateTrigger t m, MonadSample t m, MonadHold t m
139120 , MonadFix m
140121 ) => MonadWidget t (Widget t (Gui t h m)) where
@@ -180,17 +161,19 @@ mainWidget w = runWebGUI $ \webView -> do
180161 Just body <- documentGetBody doc
181162 attachWidget body w
182163
164+mainWidgetWithHead :: Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> IO ()
183165mainWidgetWithHead h b = runWebGUI $ \webView -> do
184166 Just doc <- liftM (fmap castToHTMLDocument) $ webViewGetDomDocument webView
185− Just head <- liftM (fmap castToHTMLElement) $ documentGetHead doc
186− attachWidget head h
167+ Just headElement <- liftM (fmap castToHTMLElement) $ documentGetHead doc
168+ attachWidget headElement h
187169 Just body <- documentGetBody doc
188170 attachWidget body b
189171
172+mainWidgetWithCss :: ByteString -> Widget Spider (Gui Spider SpiderHost (HostFrame Spider)) () -> IO ()
190173mainWidgetWithCss css w = runWebGUI $ \webView -> do
191174 Just doc <- liftM (fmap castToHTMLDocument) $ webViewGetDomDocument webView
192− Just head <- liftM (fmap castToHTMLElement) $ documentGetHead doc
193− htmlElementSetInnerHTML head $ "<style>" <> T.unpack (decodeUtf8 css) <> "</style>" --TODO: Fix this
175+ Just headElement <- liftM (fmap castToHTMLElement) $ documentGetHead doc
176+ htmlElementSetInnerHTML headElement $ "<style>" <> T.unpack (decodeUtf8 css) <> "</style>" --TODO: Fix this
194177 Just body <- documentGetBody doc
195178 attachWidget body w
196179
@@ -201,21 +184,18 @@ attachWidget rootElement w = runSpiderHost $ do --TODO: It seems to re-run this
201184 rec let guiEnv = GuiEnv doc (writeChan frames . runSpiderHost) runWithActions :: GuiEnv Spider SpiderHost
202185 runWithActions dm = do
203186 voidActionNeeded <- fireEventsAndRead dm $ do
204− sequence =<< readEvent voidAction
187+ sequence =<< readEvent voidActionHandle
205188 runHostFrame $ runGui (sequence_ voidActionNeeded) guiEnv
206189 Just df <- liftIO $ documentCreateDocumentFragment doc
207190 (result, voidAction) <- runHostFrame $ flip runGui guiEnv $ do
208− (result, postBuild, voidAction) <- runWidget df w
191+ (r, postBuild, va) <- runWidget df w
209192 postBuild
210− return (result, voidAction)
193+ return (r, va)
211194 liftIO $ htmlElementSetInnerHTML rootElement ""
212− liftIO $ nodeAppendChild rootElement $ Just df
213− subscribeEvent voidAction --TODO: Should be unnecessary
214−-- currentFrame <- liftIO $ newEmptyMVar
215−-- idleAdd (tryTakeMVar currentFrame >>= maybe (return ()) id >> return True) priorityLow --TODO: avoid wasting CPU here
216−-- forkIO $ forever $ putMVar currentFrame =<< readChan frames
195+ _ <- liftIO $ nodeAppendChild rootElement $ Just df
196+ voidActionHandle <- subscribeEvent voidAction --TODO: Should be unnecessary
217197 --postGUISync seems to leak memory on GHC (unknown on GHCJS)
218− liftIO $ forkIO $ forever $ postGUISync =<< readChan frames -- postGUISync is necessary to prevent segfaults in GTK, which is not thread-safe
198+ _ <- liftIO $ forkIO $ forever $ postGUISync =<< readChan frames -- postGUISync is necessary to prevent segfaults in GTK, which is not thread-safe
219199 return result
220200
221201--type MonadWidget t h m = (t ~ Spider, h ~ Gui Spider SpiderHost (HostFrame Spider), m ~ Widget t h, Monad h, MonadHold t h, HasDocument h, MonadSample t h, MonadRef h, MonadIO h, Functor (Event t), Functor h, Reflex t) -- Locking down these types seems to help a little in GHCJS, but not really in GHC
src/Reflex/Dom/Widget/Basic.hs+30−31
@@ -14,18 +14,16 @@ import qualified Data.Set as Set
1414import Data.Dependent.Sum (DSum (..))
1515import Control.Monad.Trans
1616import Control.Monad.Reader
17−import Control.Monad.State
18−import Control.Monad.Ref
17+import Control.Monad.State hiding (state)
1918import GHCJS.DOM.Node
2019import GHCJS.DOM.UIEvent
21−import GHCJS.DOM.EventM (event, Signal, EventM)
20+import GHCJS.DOM.EventM (event, EventM)
2221import GHCJS.DOM.Document
2322import GHCJS.DOM.Element
2423import GHCJS.DOM.HTMLElement
2524import GHCJS.DOM.Types hiding (Widget (..), unWidget, Event)
2625import GHCJS.DOM.NamedNodeMap
27−import Control.Lens
28−import Data.Monoid
26+import Control.Lens hiding (element, children)
2927import Data.These
3028import Data.Align
3129
@@ -121,7 +119,7 @@ dyn child = do
121119 runFrameWithTriggerRef newChildBuiltTriggerRef (result, voidActions)
122120 postBuild
123121 Just p <- liftIO $ nodeGetParentNode endPlaceholder
124− liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
122+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
125123 return ()
126124 schedulePostBuild $ do
127125 c <- sample $ current child
@@ -151,7 +149,7 @@ widgetHold child0 newChild = do
151149 case mp of
152150 Nothing -> return () --TODO: Is this right?
153151 Just p -> do
154− liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
152+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
155153 return ()
156154 return ()
157155 addVoidAction $ ffor newChild $ \c -> do
@@ -163,7 +161,6 @@ widgetHold child0 newChild = do
163161listWithKey :: (Ord k, MonadWidget t m) => Dynamic t (Map k v) -> (k -> Dynamic t v -> m a) -> m (Dynamic t (Map k a))
164162listWithKey vals mkChild = do
165163 doc <- askDocument
166− startPlaceholder <- text' ""
167164 endPlaceholder <- text' ""
168165 (newChildren, newChildrenTriggerRef) <- newEventWithTriggerRef
169166 performEvent_ $ fmap (const $ return ()) newChildren --TODO: Get rid of this hack
@@ -182,9 +179,9 @@ listWithKey vals mkChild = do
182179 (result, postBuild, voidAction) <- buildChild df k v
183180 return ((result, voidAction), postBuild)
184181 runFrameWithTriggerRef newChildrenTriggerRef $ fmap fst initialState --TODO: Do all these in a single runFrame
185− sequence $ fmap snd initialState
182+ sequence_ $ fmap snd initialState
186183 Just p <- liftIO $ nodeGetParentNode endPlaceholder
187− liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
184+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
188185 return ()
189186 addVoidAction $ flip fmap (updated vals) $ \newVals -> do
190187 curState <- sample children
@@ -202,7 +199,7 @@ listWithKey vals mkChild = do
202199 Nothing -> endPlaceholder
203200 Just (_, ((_, (start, _)), _)) -> start
204201 Just p <- liftIO $ nodeGetParentNode placeholder
205− liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
202+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
206203 return $ Just s
207204 These state _ -> do
208205 return $ Just state
@@ -213,7 +210,6 @@ listWithKey vals mkChild = do
213210listWithKey' :: forall t m k v a. (Ord k, MonadWidget t m) => Map k v -> Event t (Map k (Maybe v)) -> (k -> v -> Event t v -> m a) -> m (Dynamic t (Map k a))
214211listWithKey' initialVals valsChanged mkChild = do
215212 doc <- askDocument
216− startPlaceholder <- text' ""
217213 endPlaceholder <- text' ""
218214 (newChildren, newChildrenTriggerRef) <- newEventWithTriggerRef
219215-- performEvent_ $ fmap (const $ return ()) newChildren --TODO: Get rid of this hack
@@ -226,12 +222,12 @@ listWithKey' initialVals valsChanged mkChild = do
226222 result <- mkChild k v $ select childValChangedSelector $ Const2 k
227223 childEnd <- text' ""
228224 return (result, (childStart, childEnd))
229− Just df <- liftIO $ documentCreateDocumentFragment doc
230− initialState <- iforM initialVals $ \k v -> subWidgetWithVoidActions (toNode df) $ wrapChild k v --Note: we have to use subWidgetWithVoidActions rather than runWidget here, because running post-build actions during build can cause not-yet-constructed values to be read
225+ Just dfOrig <- liftIO $ documentCreateDocumentFragment doc
226+ initialState <- iforM initialVals $ \k v -> subWidgetWithVoidActions (toNode dfOrig) $ wrapChild k v --Note: we have to use subWidgetWithVoidActions rather than runWidget here, because running post-build actions during build can cause not-yet-constructed values to be read
231227 children <- holdDyn initialState newChildren
232228 addVoidAction $ switch $ fmap (mergeWith (>>) . map snd . Map.elems) $ current children
233− Just p <- liftIO $ nodeGetParentNode endPlaceholder
234− liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
229+ Just pOrig <- liftIO $ nodeGetParentNode endPlaceholder
230+ _ <- liftIO $ nodeInsertBefore pOrig (Just dfOrig) (Just endPlaceholder)
235231 addVoidAction $ flip fmap valsChanged $ \newVals -> do
236232 curState <- sample $ current children
237233 --TODO: Should we remove the parent from the DOM first to avoid reflows?
@@ -246,7 +242,7 @@ listWithKey' initialVals valsChanged mkChild = do
246242 let s = (childResult, childVoidAction)
247243 modify (>>childPostBuild)
248244 Just p <- liftIO $ nodeGetParentNode end
249− liftIO $ nodeInsertBefore p (Just df) (Just end)
245+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just end)
250246 return $ Just s
251247 That Nothing -> return Nothing -- Deleting non-existent child
252248 That (Just v) -> do -- Creating new child
@@ -258,7 +254,7 @@ listWithKey' initialVals valsChanged mkChild = do
258254 Nothing -> endPlaceholder
259255 Just (_, ((_, (start, _)), _)) -> start
260256 Just p <- liftIO $ nodeGetParentNode placeholder
261− liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
257+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
262258 return $ Just s
263259 This state -> do -- No change
264260 return $ Just state
@@ -273,7 +269,6 @@ listViewWithKey vals mkChild = liftM (switch . fmap mergeMap) $ listViewWithKey'
273269listViewWithKey' :: (Ord k, MonadWidget t m) => Dynamic t (Map k v) -> (k -> Dynamic t v -> m a) -> m (Behavior t (Map k a))
274270listViewWithKey' vals mkChild = do
275271 doc <- askDocument
276− startPlaceholder <- text' ""
277272 endPlaceholder <- text' ""
278273 (newChildren, newChildrenTriggerRef) <- newEventWithTriggerRef
279274 performEvent_ $ fmap (const $ return ()) newChildren --TODO: Get rid of this hack
@@ -292,9 +287,9 @@ listViewWithKey' vals mkChild = do
292287 (result, postBuild, voidAction) <- buildChild df k v
293288 return ((result, voidAction), postBuild)
294289 runFrameWithTriggerRef newChildrenTriggerRef $ fmap fst initialState --TODO: Do all these in a single runFrame
295− sequence $ fmap snd initialState
290+ sequence_ $ fmap snd initialState
296291 Just p <- liftIO $ nodeGetParentNode endPlaceholder
297− liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
292+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just endPlaceholder)
298293 return ()
299294 addVoidAction $ flip fmap (updated vals) $ \newVals -> do
300295 curState <- sample children
@@ -312,7 +307,7 @@ listViewWithKey' vals mkChild = do
312307 Nothing -> endPlaceholder
313308 Just (_, ((_, (start, _)), _)) -> start
314309 Just p <- liftIO $ nodeGetParentNode placeholder
315− liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
310+ _ <- liftIO $ nodeInsertBefore p (Just df) (Just placeholder)
316311 return $ Just s
317312 These state _ -> do
318313 return $ Just state
@@ -336,6 +331,7 @@ selectViewListWithKey_ selection vals mkChild = do
336331--------------------------------------------------------------------------------
337332
338333-- | s and e must both be children of the same node and s must precede e
334+deleteBetweenExclusive :: (IsNode start, IsNode end) => start -> end -> IO ()
339335deleteBetweenExclusive s e = do
340336 mCurrentParent <- nodeGetParentNode e -- May be different than it was at initial construction, e.g., because the parent may have dumped us in from a DocumentFragment
341337 case mCurrentParent of
@@ -344,19 +340,21 @@ deleteBetweenExclusive s e = do
344340 let go = do
345341 Just x <- nodeGetPreviousSibling e -- This can't be Nothing because we should hit 's' first
346342 when (unNode (toNode s) /= unNode (toNode x)) $ do
347− nodeRemoveChild currentParent $ Just x
343+ _ <- nodeRemoveChild currentParent $ Just x
348344 go
349345 go
350346
351347-- | s and e must both be children of the same node and s must precede e
348+deleteBetweenInclusive :: (IsNode start, IsNode end) => start -> end -> IO ()
352349deleteBetweenInclusive s e = do
353350 Just currentParent <- nodeGetParentNode e -- May be different than it was at initial construction, e.g., because the parent may have dumped us in from a DocumentFragment
354351 let go = do
355352 Just x <- nodeGetPreviousSibling e -- This can't be Nothing because we should hit 's' first
356− nodeRemoveChild currentParent $ Just x
353+ _ <- nodeRemoveChild currentParent $ Just x
357354 when (unNode (toNode s) /= unNode (toNode x)) go
358355 go
359− nodeRemoveChild currentParent $ Just e
356+ _ <- nodeRemoveChild currentParent $ Just e
357+ return ()
360358
361359--------------------------------------------------------------------------------
362360-- Adapters
@@ -398,7 +396,7 @@ elAttr elementTag attrs child = do
398396
399397{-# INLINABLE el' #-}
400398el' :: forall t m a. MonadWidget t m => String -> m a -> m (El t, a)
401−el' tag child = elAttr' tag (Map.empty :: AttributeMap) child
399+el' elementTag child = elAttr' elementTag (Map.empty :: AttributeMap) child
402400
403401{-# INLINABLE elAttr' #-}
404402elAttr' :: forall t m a. MonadWidget t m => String -> Map String String -> m a -> m (El t, a)
@@ -415,15 +413,16 @@ elDynAttr elementTag attrs child = do
415413
416414{-# INLINABLE el #-}
417415el :: forall t m a. MonadWidget t m => String -> m a -> m a
418−el tag child = elAttr tag Map.empty child
416+el elementTag child = elAttr elementTag Map.empty child
419417
420418elClass :: forall t m a. MonadWidget t m => String -> String -> m a -> m a
421−elClass tag c child = elAttr tag ("class" =: c) child
419+elClass elementTag c child = elAttr elementTag ("class" =: c) child
422420
423421--------------------------------------------------------------------------------
424422-- Copied and pasted from Reflex.Widget.Class
425423--------------------------------------------------------------------------------
426424
425+list :: (MonadWidget t m, Ord k) => Dynamic t (Map k v) -> (Dynamic t v -> m a) -> m (Dynamic t (Map k a))
427426list dm mkChild = listWithKey dm (\_ dv -> mkChild dv)
428427
429428elDynHtml' :: MonadWidget t m => String -> Dynamic t String -> m (El t)
@@ -492,7 +491,7 @@ tableDynAttr :: forall t m r k v. (MonadWidget t m, Show k, Ord k) => String ->
492491tableDynAttr klass cols dRows rowAttrs = elAttr "div" (Map.singleton "style" "zoom: 1; overflow: auto; background: white;") $ do
493492 elAttr "table" (Map.singleton "class" klass) $ do
494493 el "thead" $ el "tr" $ do
495− mapM (\(h, _) -> el "th" $ text h) cols
494+ mapM_ (\(h, _) -> el "th" $ text h) cols
496495 el "tbody" $ do
497496 listWithKey dRows (\k r -> do
498497 dAttrs <- rowAttrs k
@@ -508,7 +507,7 @@ tabDisplay ulClass activeClass tabItems = do
508507 holdDyn Nothing $ fmap Just eTabClicks :: m (Dynamic t (Maybe k))
509508 divClass "" $ do
510509 let dTabs :: Dynamic t (Map k (String, m ())) = constDyn tabItems
511− listWithKey dTabs (\k dTab -> do
510+ _ <- listWithKey dTabs (\k dTab -> do
512511 dAttrs <- mapDyn (\sel -> do
513512 let t1 = listToMaybe $ Map.keys tabItems
514513 if sel == Just k || (sel == Nothing && t1 == Just k) then Map.empty else Map.singleton "style" "display:none;") dCurrentTab
@@ -526,5 +525,5 @@ tabDisplay ulClass activeClass tabItems = do
526525unsafePlaceElement :: MonadWidget t m => HTMLElement -> m (El t)
527526unsafePlaceElement e = do
528527 p <- askParent
529− liftIO $ nodeAppendChild p $ Just e
528+ _ <- liftIO $ nodeAppendChild p $ Just e
530529 wrapElement e
src/Reflex/Dom/Widget/Input.hs+2−5
@@ -1,18 +1,15 @@
11{-# LANGUAGE ConstraintKinds, TypeFamilies, FlexibleContexts, DataKinds, GADTs, ScopedTypeVariables, FlexibleInstances, RecursiveDo #-}
22module Reflex.Dom.Widget.Input where
33
4−import Prelude hiding (forM_)
4+import Prelude
55
66import Reflex.Dom.Class
77import Reflex.Dom.Widget.Basic
88
99import Reflex
1010import Reflex.Host.Class
11−import Data.Map (Map)
12−import GHCJS.DOM.Document
1311import GHCJS.DOM.HTMLInputElement
1412import GHCJS.DOM.HTMLTextAreaElement
15−import GHCJS.DOM.Node
1613import GHCJS.DOM.Element
1714import GHCJS.DOM.HTMLSelectElement
1815import GHCJS.DOM.EventM
@@ -21,7 +18,6 @@ import Data.Monoid
2118import Data.Map as Map
2219import Control.Monad hiding (forM_)
2320import Control.Monad.IO.Class
24−import Control.Lens
2521import Data.Default
2622import Data.Maybe
2723import Safe
@@ -116,6 +112,7 @@ data TextArea t
116112textArea :: MonadWidget t m => String -> Event t String -> Dynamic t (Map String String) -> m (TextArea t)
117113textArea initial eSet attrs = do
118114 e <- liftM castToHTMLTextAreaElement $ buildEmptyElement "textarea" attrs
115+ liftIO $ htmlTextAreaElementSetValue e initial
119116 postGui <- askPostGui
120117 runWithActions <- askRunWithActions
121118 eChangeFocus <- newEventWithTrigger $ \eChangeFocusTrigger -> do
src/Reflex/Dom/Xhr.hs+5−7
@@ -3,7 +3,6 @@ module Reflex.Dom.Xhr where
33
44#ifdef __GHCJS__
55import Control.Concurrent
6−import Control.Concurrent.MVar
76import Control.Lens
87import Control.Monad
98import Control.Monad.IO.Class
@@ -14,7 +13,6 @@ import Data.Map (Map)
1413import qualified Data.Map as Map
1514import Data.Maybe
1615import Data.Text (Text)
17−import qualified Data.Text as T
1816import Data.Text.Encoding
1917import GHCJS.Foreign
2018import GHCJS.Types
@@ -62,9 +60,9 @@ newXMLHttpRequest req cb = do
6260 True
6361 (fromMaybe "" $ _xhrRequestConfig_user c)
6462 (fromMaybe "" $ _xhrRequestConfig_password c)
65− iforM (_xhrRequestConfig_headers c) $ xmlHttpRequestSetRequestHeader xhr
63+ iforM_ (_xhrRequestConfig_headers c) $ xmlHttpRequestSetRequestHeader xhr
6664 maybe (return ()) (xmlHttpRequestSetResponseType xhr . toJSString) (_xhrRequestConfig_responseType c)
67− xmlHttpRequestOnreadystatechange xhr $ do
65+ _ <- xmlHttpRequestOnreadystatechange xhr $ do
6866 readyState <- liftIO $ xmlHttpRequestGetReadyState xhr
6967 if readyState == 4
7068 then do
@@ -77,15 +75,15 @@ newXMLHttpRequest req cb = do
7775
7876performRequestAsync :: MonadWidget t m => Event t XhrRequest -> m (Event t XhrResponse)
7977performRequestAsync req = performEventAsync $ ffor req $ \r cb -> do
80− liftIO $ newXMLHttpRequest r cb
78+ _ <- liftIO $ newXMLHttpRequest r cb
8179 return ()
8280
8381performRequestsAsync :: (Traversable f, MonadWidget t m) => Event t (f XhrRequest) -> m (Event t (f XhrResponse))
8482performRequestsAsync req = performEventAsync $ ffor req $ \rs cb -> do
85− liftIO $ do
83+ _ <- liftIO $ do
8684 resps <- forM rs $ \r -> do
8785 resp <- newEmptyMVar
88− newXMLHttpRequest r $ putMVar resp
86+ _ <- newXMLHttpRequest r $ putMVar resp
8987 return resp
9088 forkIO $ cb =<< forM resps takeMVar
9189 return ()