How do I import in GHCJS a Javascript function like the following ?
xs.subscribe(function(x) { console.log(x) })
I tried various combinations of the following without success:
data Observable_
data Disposable_
type Observable a = JSRef Observable_
type Disposable = JSRef ()
foreign import javascript unsafe "$1.subscribe($2)"
rx_subscribe :: Observable a -> JSRef (a -> IO()) -> IO Disposable
Any help is appreciated, and links to documentation of the GHCJS FFI.
Thanks
Thanks to the guys on the GHCJS IRC Channel I got the answer:
foreign import javascript safe "$1.subscribe($2)"
rx_subscribe :: Observable a -> JSFun (a -> IO()) -> IO Disposable
subscribe :: FromJSRef a => (a -> IO()) -> Observable a -> IO Disposable
subscribe f xs = syncCallback1 True True f' >>= rx_subscribe xs
where f' x = fromJSRef x >>= f . fromJust
Thank You
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With