hplayground 0.1.2.1 → 0.1.2.2
raw patch · 3 files changed
+33/−21 lines, 3 filesdep ~haste-perch
Dependency ranges changed: haste-perch
Files
- hplayground.cabal +3/−3
- src/Haste/HPlay/View.hs +15/−15
- src/Haste/HPlay/WebSockets.hs +15/−3
hplayground.cabal view
@@ -1,5 +1,5 @@ name: hplayground -version: 0.1.2.1 +version: 0.1.2.2 cabal-version: >=1.8 build-type: Simple license: BSD3 @@ -27,13 +27,13 @@ if flag(haste-inst) build-depends: base >4.0 && <5, transformers -any, containers -any, - data-default -any, monads-tf -any, haste-lib -any, haste-perch -any + data-default -any, monads-tf -any, haste-lib -any, haste-perch >= 0.1.0.5 exposed: True buildable: True else build-depends: base >4.0 && <5, transformers -any, containers -any, data-default -any, monads-tf -any, haste-compiler -any, - haste-perch -any + haste-perch >= 0.1.0.5 exposed: True buildable: True exposed-modules: Haste.HPlay.View Haste.HPlay.Cell, Haste.HPlay.WebSockets
src/Haste/HPlay/View.hs view
@@ -1067,19 +1067,7 @@ return $ FormElm render' mx -getCont ::(StateType m ~ MFlowState, MonadState m) => m EventF -getCont = gets process -runCont :: EventF -> IO () -runCont (EventF x fs)= do runIt x (unsafeCoerce fs); return () - where - runIt x fs= runBody $ x >>= compose fs - - - - compose []= const empty - compose ((f,id): fs)= \x -> at id Insert (f x) >>= compose fs - -- addEvent :: Perch -> Event IO a -> a -> Perch -- addEvent be event action= Perch $ \e -> do -- e' <- build be e @@ -1136,7 +1124,21 @@ liftIO f runView $ identified id w +-- getting and running continuations +getCont ::(StateType m ~ MFlowState, MonadState m) => m EventF +getCont = gets process + +runCont :: EventF -> IO () +runCont (EventF x fs)= do runIt x (unsafeCoerce fs); return () + where + runIt x fs= runBody $ x >>= compose fs + + + + compose []= const empty + compose ((f,id): fs)= \x -> at id Insert (f x) >>= compose fs + globalState= unsafePerformIO $ newMVar mFlowState0 -- | run the widget as the content of a DOM element, the id is passed as parameter. All the @@ -1255,9 +1257,7 @@ runCont cont -- runIt x (unsafeCoerce fs) return () -instance JSType JSString where - toJSString x= x - fromJSString x= Just x +
src/Haste/HPlay/WebSockets.hs view
@@ -8,8 +8,14 @@ -- Stability : experimental -- Portability : -- --- | +-- | Hplayground WebSockets have de-inversion of control. it uses wsAsk for syncronous +-- request-responses. -- +-- wsAsk can also handle asynchronous traffic too since it catches every received +-- message, not only the next message +-- +-- For an example, see <http://tryplayg.herokuapp.com/try/hplay-sockets.hs/edit> +-- ----------------------------------------------------------------------------- {-# LANGUAGE EmptyDataDecls, OverloadedStrings #-} module Haste.HPlay.WebSockets( @@ -77,10 +83,11 @@ return $ FormElm noHtml Nothing where closes :: WebSocket -> WSOnError -> IO() - closes ws onclose= ffi "(function(ws){\ - \ws.onclose = function(ws,onclose) {B(A(onclose,[0]));};\ + closes ws onclose= ffi "(function(ws,onclose){\ + \ws.onclose = function(e) {B(A(onclose,[0]));};\ \ws.close()})" +-- | open the socket and continue the flow when it is opened. wsOpen :: URL -> Widget SockId wsOpen url = View $ do id <- genNewId @@ -110,6 +117,11 @@ \return ws;\ \})" +-- | syncronous request-responses. +-- wsAsk can also handle asynchronous traffic too since it catches every received +-- message, not only the next message and executes the rest of the computation +-- as is usual in a active widget +-- wsAsk :: (JSType a,JSType b) => SockId -> a -> Widget b wsAsk id x = View $ do cont <- getCont