MrLeebo/redux-supermodel

Actions are hard to distinguish in redux-logger

Closed this issue · 1 comments

Since everything uses the same action types, if you load several resources at the same time, it is not easy to tell them apart in the console output with redux-logger.

Simplest solution is probably to just put the resource name in the action type, but I will need to look and see if I can find a more idiomatic solution.

redux-logger has the option to pass a titleFormatter function when you configure it. I think it is preferable to add the resource name using a formatter like this so that the action types stay predictable.

import createLogger from 'redux-logger';

function titleFormatter(action, time, took) {
  const timePart = time || ''
  const tookPart = took && `(in ${took.toFixed(2)} ms)` || ''

  const resourceName = action.meta && action.meta.resourceName
  if (action.type.startsWith('@@redux-supermodel/') && resourceName) {
    return `action @ ${timePart} ${action.type} (${resourceName}) ${tookPart}`
  }

  return `action @ ${timePart} ${action.type} ${tookPart}`
}

export default function configureLogger(){
  return createLogger({
    level: 'info',
    collapsed: true,
    titleFormatter
  })
}