Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minification breaks protocols #171

Open
LeXofLeviafan opened this issue Feb 8, 2021 · 4 comments
Open

Minification breaks protocols #171

LeXofLeviafan opened this issue Feb 8, 2021 · 4 comments

Comments

@LeXofLeviafan
Copy link
Contributor

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:

  • Change protocols implementation to not rely on method names
  • Set the name property externally with Object.defineProperty():
    Object.defineProperty(function() {}, 'name', {value: 'foo'})
@LeXofLeviafan
Copy link
Contributor Author

LeXofLeviafan commented Feb 8, 2021

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
Copy link
Collaborator

Gozala commented Feb 18, 2021

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
Copy link
Contributor Author

…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
Copy link
Collaborator

chr15m commented Apr 14, 2022

A reagent/re-frame imitation that uses Mithril instead

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants