wisp-lang / wisp

A little Clojure-like LISP in JavaScript
https://gozala.github.io/wisp/
Other
982 stars 69 forks source link

Minification breaks protocols #171

Open LeXofLeviafan opened 3 years ago

LeXofLeviafan commented 3 years ago

Protocols rely on function names, which get shortened by code minifiers. Moreover, they (at least within one protocol definition) tend do be replaced by the same identifier, so in runtime an implementation of a minified protocol will only have one method (the one defined latest).

Possible fixes:

LeXofLeviafan commented 3 years ago

Another option would be to implement multimethods and use that instead. I have a solid idea how to define a simple imitation of multimethods in JS (by relying on Map or falling back on dicts) but it may take some effort to figure out how to do it in Wisp (though I guess it's possible to make a plain macro).

Gozala commented 3 years ago

For what it's worth I had something along those lines https://github.com/Gozala/protocol, however I thought that instroducing dependency was not ideal because wisp tried really hard to not introduce any external dependencies.

Another approach to address minifier issue could be to use identifier as opposed to name directly, meaning protocol method could be added field e.g. id and protocol implementations that could just use method.id instead of names.

LeXofLeviafan commented 2 years ago

…Incidentally, a working multimethods implementation can be found in my mreframe library (it's used there to implement atoms based on immediate type dispatch).

chr15m commented 2 years ago

A reagent/re-frame imitation that uses Mithril instead

Nice!