patronum icon indicating copy to clipboard operation
patronum copied to clipboard

Add custom names support for `debug`

Open AlexandrHoroshih opened this issue 3 years ago • 1 comments

Sometimes it is needed to log some unit updates with custom naming, so it is easier to read them in context

It can be simply achieved by using object shape:

debug({
 brokenStore: $a,
 someEvent: abc
})

debug({
  trace: true
}, {
 brokenStore: $a,
 someEvent: abc
})

Keys of the object will be treated as custom names for these units

Also there is maybe a need to provide custom name for some unit, which is logged not directly, but via tracing:

const $abc = combine([$a, $b, $c])

sample({
 clock: $abc,
 target: someEvent
})

debug({
  trace: true,
  names: {
     customStoreName: $abc,
  }
}, someEvent)

// debug will log someEvent's updates traces with $abc named as customStoreName

AlexandrHoroshih avatar Aug 06 '22 09:08 AlexandrHoroshih

I think the first form can be error-prone because it conflicts with the first argument as a config.

debug({
 brokenStore: $a,
 someEvent: abc,
})

sergeysova avatar Aug 06 '22 10:08 sergeysova