Open LeXofLeviafan opened 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).
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.
…Incidentally, a working multimethods implementation can be found in my mreframe
library (it's used there to implement atoms based on immediate type dispatch).
A reagent/re-frame imitation that uses Mithril instead
Nice!
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:
name
property externally withObject.defineProperty()
: