data-point icon indicating copy to clipboard operation
data-point copied to clipboard

Add debug reducer helper

Open raingerber opened this issue 7 years ago • 0 comments
trafficstars

Problem description:

There is no way to set breakpoints on path reducers, which makes debugging more difficult.

Suggested solution:

Add a debug reducer helper.


const { debug } = require('data-point').helpers

const reducer = {
  // this creates a breakpoint when this reducer is executed,
  // which provides a chance to inspect the input data
  a: debug('$a')
}

// it should be functionally similar to the code below:

const reducer = {
  a: [
    (input, acc) => {
      debugger
      return input
    },
    '$a'
  ]
}

debug could also take a function as a second parameter, and this function would be used to set a conditional breakpoint.

const reducer = {
  a: debug('$a', input => input === 'some-value')
}

// this would be functionally similar to this code:

const reducer = {
  a: [
    (input, acc) => {
      // this would execute the input => input === 'some-value' function
      if (conditionIsTrue(input, acc)) {
        debugger
      }

      return input
    },
    '$a'
  ]
}

raingerber avatar Jun 25 '18 19:06 raingerber