on develop help sign in
Merge remote-tracking branch 'origin/develop' into fix-dyn-pattern-match
e97f312Ryan Trinkle
README.md+4
@@ -5,9 +5,13 @@ Reflex-DOM is a framework for building web applications in Haskell, based on the
5
5
6Comprehensive documentation is still a work in progress, but a [demo](https://github.com/ryantrinkle/try-reflex) is available and an introductory talk is available at [Part 1](https://www.youtube.com/watch?v=mYvkcskJbc4) / [Part 2](https://www.youtube.com/watch?v=3qfc9XFVo2c) ([Slides](https://obsidian.systems/reflex-nyhug/)).
6Comprehensive documentation is still a work in progress, but a [demo](https://github.com/ryantrinkle/try-reflex) is available and an introductory talk is available at [Part 1](https://www.youtube.com/watch?v=mYvkcskJbc4) / [Part 2](https://www.youtube.com/watch?v=3qfc9XFVo2c) ([Slides](https://obsidian.systems/reflex-nyhug/)).
7
7
8+A summary of Reflex-DOM functions is available in the [quick reference](Quickref.md).
9+
8### Additional resources
10### Additional resources
9[try reflex](https://github.com/ryantrinkle/try-reflex)
11[try reflex](https://github.com/ryantrinkle/try-reflex)
10
12
11[reddit/r/reflexfrp](http://www.reddit.com/r/reflexfrp)
13[reddit/r/reflexfrp](http://www.reddit.com/r/reflexfrp)
12
14
15+[reflex-examples](https://github.com/reflex-frp/reflex-examples)
16+
13irc.freenode.net #reflex-frp
17irc.freenode.net #reflex-frp
reflex-dom.cabal+1
@@ -74,6 +74,7 @@ library
74 Reflex.Dom.Widget.Lazy
74 Reflex.Dom.Widget.Lazy
75 Reflex.Dom.Widget.Resize
75 Reflex.Dom.Widget.Resize
76 Reflex.Dom.Xhr
76 Reflex.Dom.Xhr
77+ Reflex.Dom.Location
77 Foreign.JavaScript.TH
78 Foreign.JavaScript.TH
78 other-modules:
79 other-modules:
79 Reflex.Dom.Internal.Foreign
80 Reflex.Dom.Internal.Foreign
src-ghc/Reflex/Dom/Internal/Foreign.hs+17
@@ -13,6 +13,7 @@ import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSBase
13import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef
13import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef
14import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSStringRef
14import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSStringRef
15import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSValueRef
15import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSValueRef
16+import Graphics.UI.Gtk.WebKit.JavaScriptCore.WebFrame
16import Graphics.UI.Gtk.WebKit.WebView
17import Graphics.UI.Gtk.WebKit.WebView
17import Graphics.UI.Gtk.WebKit.Types hiding (Event, Widget, unWidget)
18import Graphics.UI.Gtk.WebKit.Types hiding (Event, Widget, unWidget)
18import Graphics.UI.Gtk.WebKit.WebSettings
19import Graphics.UI.Gtk.WebKit.WebSettings
@@ -99,3 +100,19 @@ fromJSStringMaybe c t = do
99 peekCString ps
100 peekCString ps
100 return $ Just s
101 return $ Just s
101
102
103+getLocationHost :: WebView -> IO String
104+getLocationHost wv = do
105+ c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
106+ script <- jsstringcreatewithutf8cstring "location.host"
107+ lh <- jsevaluatescript c script nullPtr nullPtr 1 nullPtr
108+ lh' <- fromJSStringMaybe c lh
109+ return $ maybe "" id lh'
110+
111+getLocationProtocol :: WebView -> IO String
112+getLocationProtocol wv = do
113+ c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
114+ script <- jsstringcreatewithutf8cstring "location.protocol"
115+ lp <- jsevaluatescript c script nullPtr nullPtr 1 nullPtr
116+ lp' <- fromJSStringMaybe c lp
117+ return $ maybe "" id lp'
118+
src-ghc/Reflex/Dom/WebSocket/Foreign.hs−16
@@ -26,22 +26,6 @@ data JSWebSocket = JSWebSocket { wsValue :: JSValueRef
26 , wsContext :: JSContextRef
26 , wsContext :: JSContextRef
27 }
27 }
28
28
29−getLocationHost :: WebView -> IO String
30−getLocationHost wv = do
31− c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
32− script <- jsstringcreatewithutf8cstring "location.host"
33− lh <- jsevaluatescript c script nullPtr nullPtr 1 nullPtr
34− lh' <- fromJSStringMaybe c lh
35− return $ maybe "" id lh'
36−
37−getLocationProtocol :: WebView -> IO String
38−getLocationProtocol wv = do
39− c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
40− script <- jsstringcreatewithutf8cstring "location.protocol"
41− lp <- jsevaluatescript c script nullPtr nullPtr 1 nullPtr
42− lp' <- fromJSStringMaybe c lp
43− return $ maybe "" id lp'
44−
45newWebSocket :: WebView -> String -> (ByteString -> IO ()) -> IO () -> IO JSWebSocket
29newWebSocket :: WebView -> String -> (ByteString -> IO ()) -> IO () -> IO JSWebSocket
46newWebSocket wv url onMessage onClose = do
30newWebSocket wv url onMessage onClose = do
47 c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
31 c <- webFrameGetGlobalContext =<< webViewGetMainFrame wv
src-ghcjs/Reflex/Dom/Internal/Foreign.hs+21−1
@@ -1,9 +1,29 @@
1−module Reflex.Dom.Internal.Foreign (runWebGUI) where
1+{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI, CPP #-}
2
2
3+module Reflex.Dom.Internal.Foreign ( runWebGUI
4+ , module Reflex.Dom.Internal.Foreign
5+ ) where
6+
7+import Control.Monad
3import GHCJS.DOM
8import GHCJS.DOM
4import GHCJS.DOM.Types
9import GHCJS.DOM.Types
5import GHCJS.Types
10import GHCJS.Types
6import Data.Function
11import Data.Function
12+import GHCJS.Foreign
13+
14+#define JS(name, js, type) foreign import javascript unsafe js name :: type
7
15
8instance Eq Node where
16instance Eq Node where
9 (==) = eqRef `on` unNode
17 (==) = eqRef `on` unNode
18+
19+JS(getLocationHost_, "location.host", IO JSString)
20+
21+getLocationHost :: FromJSString r => a -> IO r
22+getLocationHost _ = liftM fromJSString getLocationHost_
23+
24+JS(getLocationProtocol_, "location.protocol", IO JSString)
25+
26+getLocationProtocol :: FromJSString r => a -> IO r
27+getLocationProtocol _ = liftM fromJSString getLocationProtocol_
28+
29+
src-ghcjs/Reflex/Dom/WebSocket/Foreign.hs−10
@@ -28,16 +28,6 @@ webSocketSend ws bs = BS.useAsCString bs $ \cStr -> do
28 ba <- extractByteArray cStr $ BS.length bs
28 ba <- extractByteArray cStr $ BS.length bs
29 webSocketSend_ (unWebSocket ws) ba
29 webSocketSend_ (unWebSocket ws) ba
30
30
31−JS(getLocationHost_, "location.host", IO JSString)
32−
33−getLocationHost :: FromJSString r => a -> IO r
34−getLocationHost _ = liftM fromJSString getLocationHost_
35−
36−JS(getLocationProtocol_, "location.protocol", IO JSString)
37−
38−getLocationProtocol :: FromJSString r => a -> IO r
39−getLocationProtocol _ = liftM fromJSString getLocationProtocol_
40−
41newWebSocket :: a -> String -> (ByteString -> IO ()) -> IO () -> IO JSWebSocket
31newWebSocket :: a -> String -> (ByteString -> IO ()) -> IO () -> IO JSWebSocket
42newWebSocket _ url onMessage onClose = do
32newWebSocket _ url onMessage onClose = do
43 onMessageFun <- syncCallback1 AlwaysRetain True $ onMessage <=< return . encodeUtf8 . fromJSString
33 onMessageFun <- syncCallback1 AlwaysRetain True $ onMessage <=< return . encodeUtf8 . fromJSString
src/Reflex/Dom.hs+2
@@ -6,6 +6,7 @@ module Reflex.Dom ( module Reflex
6 , module Reflex.Dom.Time
6 , module Reflex.Dom.Time
7 , module Reflex.Dom.WebSocket
7 , module Reflex.Dom.WebSocket
8 , module Reflex.Dom.DynamicWriter
8 , module Reflex.Dom.DynamicWriter
9+ , module Reflex.Dom.Location
9 ) where
10 ) where
10
11
11import Reflex
12import Reflex
@@ -16,3 +17,4 @@ import Reflex.Dom.Xhr
16import Reflex.Dom.Time
17import Reflex.Dom.Time
17import Reflex.Dom.WebSocket
18import Reflex.Dom.WebSocket
18import Reflex.Dom.DynamicWriter
19import Reflex.Dom.DynamicWriter
20+import Reflex.Dom.Location
src/Reflex/Dom/Location.hsnew file+3
@@ -0,0 +1,3 @@
1+module Reflex.Dom.Location (getLocationHost, getLocationProtocol) where
2+
3+import Reflex.Dom.Internal.Foreign
src/Reflex/Dom/Widget/Basic.hs+1−1
@@ -795,7 +795,7 @@ link s = linkClass s ""
795
795
796button :: MonadWidget t m => String -> m (Event t ())
796button :: MonadWidget t m => String -> m (Event t ())
797button s = do
797button s = do
798− (e, _) <- el' "button" $ text s
798+ (e, _) <- elAttr' "button" (Map.singleton "type" "button") $ text s
799 return $ domEvent Click e
799 return $ domEvent Click e
800
800
801newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }
801newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }