paf31 / purescript-jquery

Type declarations for jQuery
MIT License
30 stars 28 forks source link

Can not use purescript-jquery with <$> #24

Closed bramblex closed 8 years ago

bramblex commented 8 years ago
 -- can not work
 void $ on "click" (deleteArticleHandler) <$> select "a[data-delete]"

-- following code will work
menuLink <- select "#menuLink"
void $ on "click" (menuLinkHandler) menuLink

It will compile to the following code.

Prelude["void"](Control_Monad_Eff.functorEff)(Prelude["<$>"](Control_Monad_Eff.functorEff)(Control_Monad_Eff_JQuery.on("click")(deleteArticleHandler))(Control_Monad_Eff_JQuery.select("a[data-delete]")))(); // function didn't run in this statement

var _0 = Control_Monad_Eff_JQuery.select("#menuLink")();
return Prelude["void"](Control_Monad_Eff.functorEff)(Control_Monad_Eff_JQuery.on("click")(menuLinkHandler)(_0))();
paf31 commented 8 years ago

Is this issue with <$> or with the different selector?

garyb commented 8 years ago

I think you want to do this instead:

on "click" menuLinkHandler =<< select "#menuLink"

Or if you prefer:

select "#menuLink" >>= on "click" menuLinkHandler
bramblex commented 8 years ago

I made a mistake, I'm very sorry waste of your time. And thank you for help me.

 on "click" (deleteArticleHandler) <$> select "a[data-delete]" -- it will return a (Eff eff JQuery), not a JQuery.
paf31 commented 8 years ago

No problem, perhaps the API should be improved.