module Language.Fay.Yesod where
import Language.Fay.FFI
import Language.Fay.Prelude
data Returns a = Returns
deriving (Show, Read, Data, Typeable)
call :: (Foreign a, Foreign command)
=> (Returns a -> command)
-> (a -> Fay ())
-> Fay ()
call f g = ajaxCommand (f Returns) g
ajaxCommand :: (Foreign a, Foreign command)
=> command
-> (a -> Fay ())
-> Fay ()
ajaxCommand = ffi "jQuery['ajax']({\
\ \"url\": window['yesodFayCommandPath'], \
\ \"type\": 'POST', \
\ \"data\": { \"json\": JSON.stringify(%1) }, \
\ \"dataType\": 'json', \
\ \"success\" : %2 \
\})"