@@ -73,8 +73,6 @@ export function replaceStores(reactorState, stores) {
7373 * @return {ReactorState }
7474 */
7575export function dispatch ( reactorState , actionType , payload ) {
76- let logging = reactorState . get ( 'logger' )
77-
7876 if ( actionType === undefined && getOption ( reactorState , 'throwOnUndefinedActionType' ) ) {
7977 throw new Error ( '`dispatch` cannot be called with an `undefined` action type.' )
8078 }
@@ -83,7 +81,7 @@ export function dispatch(reactorState, actionType, payload) {
8381 let dirtyStores = reactorState . get ( 'dirtyStores' )
8482
8583 const nextState = currState . withMutations ( state => {
86- logging . dispatchStart ( reactorState , actionType , payload )
84+ getLoggerFunction ( reactorState , ' dispatchStart' ) ( reactorState , actionType , payload )
8785
8886 // let each store handle the message
8987 reactorState . get ( 'stores' ) . forEach ( ( store , id ) => {
@@ -94,13 +92,13 @@ export function dispatch(reactorState, actionType, payload) {
9492 newState = store . handle ( currState , actionType , payload )
9593 } catch ( e ) {
9694 // ensure console.group is properly closed
97- logging . dispatchError ( reactorState , e . message )
95+ getLoggerFunction ( reactorState , ' dispatchError' ) ( reactorState , e . message )
9896 throw e
9997 }
10098
10199 if ( newState === undefined && getOption ( reactorState , 'throwOnUndefinedStoreReturnValue' ) ) {
102100 const errorMsg = 'Store handler must return a value, did you forget a return statement'
103- logging . dispatchError ( reactorState , errorMsg )
101+ getLoggerFunction ( reactorState , ' dispatchError' ) ( reactorState , errorMsg )
104102 throw new Error ( errorMsg )
105103 }
106104
@@ -112,7 +110,7 @@ export function dispatch(reactorState, actionType, payload) {
112110 }
113111 } )
114112
115- logging . dispatchEnd ( reactorState , state , dirtyStores , currState )
113+ getLoggerFunction ( reactorState , ' dispatchEnd' ) ( reactorState , state , dirtyStores , currState )
116114 } )
117115
118116 const nextReactorState = reactorState
@@ -376,6 +374,17 @@ export function resetDirtyStores(reactorState) {
376374 return reactorState . set ( 'dirtyStores' , Immutable . Set ( ) )
377375}
378376
377+ export function getLoggerFunction ( reactorState , fnName ) {
378+ const logger = reactorState . get ( 'logger' )
379+ if ( ! logger ) {
380+ return noop
381+ }
382+ const fn = logger [ fnName ]
383+ return ( fn )
384+ ? fn . bind ( logger )
385+ : noop
386+ }
387+
379388/**
380389 * @param {ReactorState } reactorState
381390 * @param {CacheEntry } cacheEntry
@@ -438,3 +447,5 @@ function incrementStoreStates(storeStates, storeIds) {
438447 } )
439448 } )
440449}
450+
451+ function noop ( ) { }
0 commit comments