[refactored] mathematical operators to use _mathOperator
ClosedPublic

Authored by appsforartists on Sep 25 2017, 10:17 PM.

Details

Summary

Many operators assume the upstream value and an argument have the same shape. Typing them is not straight-forward, because it's hard to constrain the type of T in a method in TypeScript.

With some help from @justinfagnani and @rictic, we've realized that you can constrain these types by having U be the intersection of T and its valid types, and then having your argument also be of the type U.

Unfortunately, the gymnastics required to do this is noise that makes the operator implementations harder to follow. Thus, I've abstracted it all into _mathOperator and made each of the mathematical operators delegate to that method. This makes it easier to maintain those operators, and to potentially add new ones in the future. The types, and the ability to work on either numbers or points, can be shared across them.

Diff Detail

Repository
R13 material-motion/material-motion-js
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
Restricted Application added a reviewer: O2: Material Motion. · View Herald TranscriptSep 25 2017, 10:17 PM
Restricted Application added a project: Material Motion. · View Herald Transcript
Restricted Application added a reviewer: O3: Material JavaScript platform reviewers. · View Herald Transcript
Restricted Application added a reviewer: Material Motion. · View Herald Transcript
Restricted Application failed to build Restricted Buildable!Sep 25 2017, 10:20 PM

Using more semantic names for arguments in operation

Restricted Application failed to build Restricted Buildable!Sep 25 2017, 10:26 PM
featherless accepted this revision.Oct 6 2017, 2:04 PM
This revision is now accepted and ready to land.Oct 6 2017, 2:04 PM
This revision was automatically updated to reflect the committed changes.