Skip to content

有关 createLogger的transformer选项 #305

Closed
@GavinCLY

Description

@GavinCLY

const logger = createLogger({
collapsed: false, // auto-expand logged mutations
transformer (state) {
// transform the state before logging it.
// for example return only a specific sub-tree
return state.subTree
},
mutationTransformer (mutation) {
// mutations are logged in the format of { type, payload }
// we can format it any way we want.
return mutation.type
}
})

从文档中来看,transformer貌似是对console输出的state进行部分展示,例如我只输出state中的items对象,但在实际操作中并没有看到这样的效果。

是否需要将logger.js中的输出的部分修改成:
// 源码:console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', prevState);

  console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState));
  console.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation);
  console.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState));

不知道是我对transformer的理解有误,还是这的确是漏了,忘不吝赐教

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions