Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identifies promises disguised as promises. #364

Merged
merged 1 commit into from
Mar 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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