diff --git a/JavaScript/JQuery.hs b/JavaScript/JQuery.hs index b923fdf..dadc1fe 100644 --- a/JavaScript/JQuery.hs +++ b/JavaScript/JQuery.hs @@ -213,6 +213,7 @@ import Data.JSString as S (pack) import Data.JSString.Text as S (textToJSString) import Data.Text as Text (Text) import Data.Typeable +import System.IO (fixIO) default (JSString) @@ -445,19 +446,21 @@ on a et hs jq = do cb <- if hsSynchronous hs then Cb.syncCallback1 ContinueAsync (a . Event) else Cb.asyncCallback1 (a . Event) - jq_on cb et' ds hd sp sip pd jq - return (jq_off cb et' ds jq >> Cb.releaseCallback cb) + cb' <- jq_on cb et' ds hd sp sip pd jq + return (jq_off cb' et' ds jq >> Cb.releaseCallback cb) where et' = textToJSString et (pd, sp, sip, ds, hd) = convertHandlerSettings hs one :: (Event -> IO ()) -> EventType -> HandlerSettings -> JQuery -> IO (IO ()) one a et hs jq = do - cb <- if hsSynchronous hs - then Cb.syncCallback1 ContinueAsync (a . Event) - else Cb.asyncCallback1 (a . Event) - jq_one cb et' ds hd sp sip pd jq - return (jq_off cb et' ds jq >> Cb.releaseCallback cb) + cb <- fixIO $ \cb -> + let a' = \e -> Cb.releaseCallback cb >> a e + in if hsSynchronous hs + then Cb.syncCallback1 ContinueAsync (a' . Event) + else Cb.asyncCallback1 (a' . Event) + cb' <- jq_one cb et' ds hd sp sip pd jq + return (jq_off cb' et' ds jq >> Cb.releaseCallback cb) where et' = textToJSString et (pd, sp, sip, ds, hd) = convertHandlerSettings hs diff --git a/JavaScript/JQuery/Internal.hs b/JavaScript/JQuery/Internal.hs index 0e12e9a..8e7eabf 100644 --- a/JavaScript/JQuery/Internal.hs +++ b/JavaScript/JQuery/Internal.hs @@ -163,7 +163,7 @@ foreign import javascript unsafe "$8.on($2, $3, $4, h$jquery_makeListener($1, $5 -> Bool -- ^ stopImmediatePropagation -> Bool -- ^ preventDefault -> JQuery - -> IO () + -> IO (Callback a) foreign import javascript unsafe "$8.one($2, $3, $4, h$jquery_makeListener($1, $5, $6, $7))" jq_one :: Callback a -- ^ callback @@ -174,7 +174,7 @@ foreign import javascript unsafe "$8.one($2, $3, $4, h$jquery_makeListener($1, $ -> Bool -- ^ stopImmediatePropagation -> Bool -- ^ preventDefault -> JQuery - -> IO () + -> IO (Callback a) foreign import javascript unsafe "$4.off($2,$3,$1)" jq_off :: Callback a -- ^ callback diff --git a/example/Main.hs b/example/Main.hs index 1eabc52..e42be23 100644 --- a/example/Main.hs +++ b/example/Main.hs @@ -15,15 +15,15 @@ main = ready $ do myCount <- select "