Skip to content

Conversation

@buu700
Copy link

@buu700 buu700 commented Apr 27, 2017

I added a dependency on math-expression-evaluator, which as far as I can tell should handle every expected input that's currently being passed in to eval.

buu700 added a commit to buu700/web-animations-js-tmp that referenced this pull request Apr 27, 2017
@buu700
Copy link
Author

buu700 commented Apr 27, 2017

Looks like the tests are failing because they aren't configured to work with dependencies/require? Not sure how you guys want to handle all that stuff, but in any case this is more of a suggestion than a real code contribution (my change to the JS was one line).

Tests aside, it seems to be working as expected in my project that uses @angular/animations.

@buu700
Copy link
Author

buu700 commented Apr 27, 2017

Caught an edge case regression: repeatedly mousing in and out of an element with an @angular/material mdTooltip will at some point throw Mismatched interpolation arguments 0:100.

Edit: disregard this; apparently I just hadn't noticed that mexp.eval was returning a string instead of a number. Seems to be working as expected after converting it.

@buu700 buu700 force-pushed the dev branch 2 times, most recently from 35a6750 to ba5e13a Compare April 28, 2017 01:44
@bugwheels94
Copy link

bugwheels94 commented Apr 28, 2017

@buu700 Hi, I am creator of mexp. As far as I know, mexp.eval returns a Number with precision upto 15 digits. May you please tell me in which case it is returning a string?

@buu700
Copy link
Author

buu700 commented Apr 28, 2017

It looks like it's consistently returning a string in both a node repl and my browser console:

screen shot 2017-04-28 at 4 06 11 am

@bugwheels94
Copy link

I have fixed this. Now it is returning numbers in version 1.2.17

@buu700
Copy link
Author

buu700 commented Apr 28, 2017

Nice, thanks! I'll update this pr to remove parseFloat and bump up the mexp version.


(function(scope, testing) {

var mexp = require('math-expression-evaluator');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't nodejs code, require wont work here.

Copy link
Author

@buu700 buu700 May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure how you guys would want to handle dependencies, since this would be the first one. Is there a solution that would be preferred over require with a module bundler?

One option that comes to mind is something like typeof require !== 'undefined' ? require('math-expression-evaluator').eval : eval, which would accommodate both users like me who can't use eval for CSP compliance and users who want the size advantage you mentioned of not including another dependency (either by loading web-animations-js with a script tag or by configuring math-expression-evaluator as an undefined external in their module bundler).


for (var unit in matchedUnits) {
var result = eval(string.replace(new RegExp('U' + unit, 'g'), '').replace(new RegExp(taggedUnitRegExp, 'g'), '*0'));
var result = mexp.eval(string.replace(new RegExp('U' + unit, 'g'), '').replace(new RegExp(taggedUnitRegExp, 'g'), '*0'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man reason eval is used here is to keep the code size small. How large is this dependency? Further, if we're going to replace this, I think we would prefer to write the replacement inline rather than adding dependencies to this library.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's 11.7 kb.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#151 implements calc expression inline and adds 449 bytes to web-animations-next-lite.min.js. No need to add an 11.7 kb dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that's great news!

@ewilligers ewilligers closed this Jul 18, 2017
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

Successfully merging this pull request may close these issues.

4 participants