material-motion-js icon indicating copy to clipboard operation
material-motion-js copied to clipboard

Positional sugar for operators that usually take one arg

Open appsforartists opened this issue 8 years ago • 0 comments

The named arguments pattern is great for functions that take multiple arguments. We moved all operators to it in #193. However, there are some operators that usually take a single argument; they have been made harder to read and to use by the transition.

Therefore, I'm going to go back and add positional sugar for operators with one primary argument:

  • added/subtracted/multiplied/dividedBy
  • distanceFrom
  • log
  • pluck
  • isAnyOf
  • rewriteTo
  • threshold
  • startWith
  • merge
  • appendUnit
  • _map
  • _tap
  • _filter
  • _slidingWindow

For consistency, they will keep their named argument signatures as the primary entry. The positional alternative is just sugar, because this:

translate$.distanceFrom({ x: 100, y: 100 }).threshold(70).isAnyOf([ ThresholdRegion.ABOVE ]).rewriteTo(100);

is easier to read and to write than:

translate$.distanceFrom({ origin: { x: 100, y: 100 } }).threshold({ limit: 70 }).isAnyOf({ matches: [ ThresholdRegion.ABOVE ] }).rewriteTo({ value: 100 });

appsforartists avatar Oct 07 '17 05:10 appsforartists