paf31 / purescript-jquery

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

`on` Parameters #2

Closed pseudonom closed 10 years ago

pseudonom commented 10 years ago

It seems quite plausible to me that on ought to be defined like this.

foreign import on
  "function on(evt) { \
  \  return function(act) { \
  \    return function(ob) { \
  \      return function() { \
  \        return ob.on(evt, function() { \
  \          act($(this))(); \
  \        }); \
  \      }; \
  \    }; \
  \  }; \
  \}" :: forall eff a. String -> (J.JQuery -> Eff eff a) -> J.JQuery ->
        Eff (dom :: J.DOM | eff) J.JQuery

With the original definition, something like

J.select ".foo" >>= J.on "click" (J.appendText "bar")

will add "bar" to every "foo" element. The proposed definition allows both this behavior and clicked-element-specific behavior.

paf31 commented 10 years ago

I think you're right. Feel free to submit a PR or I can just fix this. For consistency we should probably use jQuery instead of $ though.