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

Minify? #3

Open
elclanrs opened this issue Oct 14, 2013 · 7 comments
Open

Minify? #3

elclanrs opened this issue Oct 14, 2013 · 7 comments

Comments

@elclanrs
Copy link

Nice script, I can see myself using this often but as-is it would break when minified, given that you're serializing the function. A workaround could be the approach that Angular takes, passing an array with the arguments as strings so they don't get mangled after minifying. Maybe something like this? Just thinking out loud:

var f = Over(
 ['msg$string', function(msg) {
   return ...;
 }],
 ['msg$string, num$number', function(msg, num) {
   return ...;
 }]
);
@matryer
Copy link
Member

matryer commented Oct 14, 2013

Great point. Can you provide some examples?

@elclanrs
Copy link
Author

See my update above.

@matryer
Copy link
Member

matryer commented Oct 14, 2013

What about this:

var f = Over({
  "string, number": function(s, n){ /* ... */ },
  "string, string, number": function(s, s2, n){ /* ... */ },
  "string, etc": function(s, etc){ /* ... */ }
});

@matryer
Copy link
Member

matryer commented Oct 14, 2013

(We could then support both versions)

@elclanrs
Copy link
Author

Yeah, that's much better than my proposed solution, looks clean.

@elclanrs
Copy link
Author

I got inspired by your script and gave it a try at building my own way following the solution you proposed. The script is very simple, it doesn't do any serialization or even throw exception, it just fallbacks to the closest signature or to an empty function. Extra arguments are always passed as an array at the end. I uploaded a little gist if you want to take a look. https://gist.github.com/elclanrs/6986187

@floatdrop
Copy link

👍 for passing object to Over. This allows optional arguments be notes more human readable, instead of $_.

var f = Over({
  "string, object?, function": function(name, options, callback){ /* ... */ },
  "string, [object], function": function(s, s2, n){ /* ... */ }
});

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