binaryage / cljs-oops

ClojureScript macros for convenient native Javascript object access.
Other
351 stars 13 forks source link

cljs-oops with methods that take arguments #12

Closed Engelberg closed 6 years ago

Engelberg commented 7 years ago

What would be the cljs-oops equivalent of:

a.e.f(x).g(y,z);

Is there a better way than:

(ocall (ocall a "e.f" x) "g" y z)

It would be nice to be able to do something similar to Clojure's .. macro, but that doesn't seem to be compatible with cljs-oops's flexible way of handling paths.

Just brainstorming here, maybe it would be possible to support the % character as a placeholder for args, like so:

(ocall a "e.f(%).g" x y z)
darwin commented 7 years ago

I like your idea, but it would take some effort to implement. We would need to support this in both static and dynamic selector case and add some diagnostics in dev mode.

Instead of .. the threading macro -> should do a similar thing:

(-> a
    (ocall "e.f" x)
    (ocall "g" y z))

I've added some tests in 9df72a5aebb46f994845e28f82acd9b87f5e6296 to see if the generated code looks fine.

Engelberg commented 7 years ago

Yeah, the threading macro definitely helps readability here. Thanks for the suggestion.

darwin commented 6 years ago

Closing because I don't want to add more complexity into "selectors" subsystem. Thanks for the suggestion, though.