Skip to content

Commit

Permalink
Identifies promises disguised as promises. (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
skellock committed Mar 12, 2017
1 parent e15e1cb commit d055e26
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/demo-react-native/App/Sagas/StartupSagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ function testFunctionNames () {
export function * startup () {
testRecursion()
testFunctionNames()
// we can yield promises to sagas now... if that's how you roll
yield new Promise(resolve => { resolve() }) // eslint-disable-line
yield put({ type: 'HELLO' })
}
11 changes: 11 additions & 0 deletions packages/reactotron-redux-saga/src/get-effect-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import { isNilOrEmpty } from 'ramdasauce'
/* eslint-disable no-cond-assign */
export default effect => {
if (!effect) return SagaConstants.UNKNOWN
if (effect instanceof Promise) {
let display
if (effect.name) { // a promise object with a manually set name prop for display reasons
display = `${SagaConstants.PROMISE}(${effect.name})`
} else if (effect.constructor instanceof Promise.constructor) { // an anonymous promise
display = SagaConstants.PROMISE
} else { // class which extends Promise, so output the name of the class to precise
display = `${SagaConstants.PROMISE}(${effect.constructor.name})`
}
return display
}
if (effect.root) return effect.saga.name
let data
if (data = asEffect.take(effect)) return data.pattern || 'channel'
Expand Down
2 changes: 2 additions & 0 deletions packages/reactotron-redux-saga/src/get-effect-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { is, asEffect } from 'redux-saga/utils'
import * as SagaConstants from './saga-constants'

export default effect => {
if (!effect) return SagaConstants.UNKNOWN
if (effect instanceof Promise) return SagaConstants.PROMISE
if (asEffect.take(effect)) return SagaConstants.TAKE
if (asEffect.put(effect)) return SagaConstants.PUT
if (asEffect.call(effect)) return SagaConstants.CALL
Expand Down
1 change: 1 addition & 0 deletions packages/reactotron-redux-saga/src/saga-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const CANCEL = 'CANCEL'
export const SELECT = 'SELECT'
export const PARALLEL = 'PARALLEL'
export const ITERATOR = 'ITERATOR'
export const PROMISE = 'PROMISE' // not from redux-saga
export const UNKNOWN = 'UNKNOWN' // not from redux-saga

// monitoring statuses
Expand Down
16 changes: 8 additions & 8 deletions packages/reactotron-redux-saga/src/saga-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ export default (reactotron, options) => {
children.push({
depth,
effectId: sourceEffectInfo.effectId,
parentEffectId: sourceEffectInfo.parentEffectId,
name: sourceEffectInfo.name,
description: sourceEffectInfo.description,
parentEffectId: sourceEffectInfo.parentEffectId || null,
name: sourceEffectInfo.name || null,
description: sourceEffectInfo.description || null,
duration: Math.round(sourceEffectInfo.duration),
status: sourceEffectInfo.status,
winner: sourceEffectInfo.winner,
loser: sourceEffectInfo.loser,
result: sourceEffectInfo.result,
extra
status: sourceEffectInfo.status || null,
winner: sourceEffectInfo.winner || null,
loser: sourceEffectInfo.loser || null,
result: sourceEffectInfo.result || null,
extra: extra || null
})

// rerun this function for our children
Expand Down

0 comments on commit d055e26

Please sign in to comment.