hplayground 0.1.2.3 → 0.1.2.4
raw patch · 4 files changed
+35/−28 lines, 4 filessetup-changed
Files
- Setup.hs +0/−2
- Setup.lhs +6/−0
- hplayground.cabal +1/−1
- src/Haste/HPlay/View.hs +28/−25
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
+ Setup.lhs view
@@ -0,0 +1,6 @@+#!/usr/bin/runhaskell +> module Main where+> import Distribution.Simple+> main :: IO ()+> main = defaultMain+
hplayground.cabal view
@@ -1,5 +1,5 @@ name: hplayground -version: 0.1.2.3 +version: 0.1.2.4 cabal-version: >=1.8 build-type: Simple license: BSD3
src/Haste/HPlay/View.hs view
@@ -75,7 +75,7 @@ import Unsafe.Coerce import Data.Maybe -import Haste +import Haste hiding (attr) import Haste.Prim import Haste.Foreign import Haste.JSON hiding ((!)) @@ -162,19 +162,19 @@ let idx= runWidgetId (strip st x) "noid" put st{process= EventF idx ( \x -> runWidgetId ( f x) id `bind` unsafeCoerce fs) } return conf - where - at id w= View $ do - FormElm render mx <- (runView w) - return $ FormElm (set render) mx - where - set render= liftIO $ do - me <- elemById id - case me of - Nothing -> return () - Just e -> do - clearChildren e - build render e - return () +-- where +-- at id w= View $ do +-- FormElm render mx <- (runView w) +-- return $ FormElm (set render) mx +-- where +-- set render= liftIO $ do +-- me <- elemById id +-- case me of +-- Nothing -> return () +-- Just e -> do +-- clearChildren e +-- build render e +-- return () resetEventCont cont= modify $ \s -> s {process= cont} @@ -1263,37 +1263,34 @@ -- | Run the widget as the content of the element with the given id. The content can -- be appended, prepended to the previous content or it can be the only content depending on the -- update method. -at :: ElemID -> UpdateMethod -> Widget a -> Widget a +at :: String -> UpdateMethod -> Widget a -> Widget a at id method w= View $ do FormElm render mx <- (runView w) return $ FormElm (set render) mx where - set render= liftIO $ do - me <- elemById id - case me of - Nothing -> return () - Just e -> case method of + set render= liftIO $ case method of Insert -> do - clearChildren e - build render e + forElems' id $ clear >> render return () Append -> do - build render e + forElems' id render return () Prepend -> do + forElems' id $ Perch $ \e -> do es <- getChildren e case es of - [] -> build render e >> return () + [] -> build render e >> return e e':es -> do span <- newElem "span" addChildBefore span e e' build render span - return() + return e -- ajax responseAjax :: IORef [(String,Maybe JSString)] responseAjax = unsafePerformIO $ newIORef [] + -- | Invoke AJAX. `ToJSString` is a class coverter to-from JavaScript strings -- `(a,b)` are the lists of parameters, a is normally `String` or `JSString`. @@ -1365,5 +1362,11 @@ #else ajaxReq= undefined #endif ++listen :: JSType event => Elem -> event -> a -> IO Bool +listen e event f= jsSetCB e (toJSString event) (mkCallback $! f) + + +foreign import ccall jsSetCB :: Elem -> JSString -> JSFun a -> IO Bool