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

Reactotron redux saga live monitor #376

Merged
merged 3 commits into from
Mar 15, 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
1 change: 1 addition & 0 deletions packages/reactotron-core-server/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default [
'state.values.change',
'state.backup.response',
'saga.task.complete',
'saga.effect.update',
'api.response',
'benchmark.report',
'display',
Expand Down
21 changes: 19 additions & 2 deletions packages/reactotron-redux-saga/src/saga-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { is } from 'redux-saga/utils'
import getEffectName from './get-effect-name'
import getEffectDescription from './get-effect-description'
import { ITERATOR, CALL, PUT, FORK, RACE, PENDING, RESOLVED, REJECTED, CANCELLED } from './saga-constants'
import { reject, values, pluck, isNil, split, pathOr, last, forEach, propEq, filter, __ } from 'ramda'
import { reject, values, pluck, isNil, split, pathOr, last, forEach, propEq, filter, __, omit, map } from 'ramda'

// creates a saga monitor
export default (reactotron, options) => {
// a lookup table of effects - keys are numbers, values are objects
const effects = {}
let effects = {}

// filtering that effect table
const byParentId = propEq('parentEffectId', __)
Expand All @@ -18,6 +18,9 @@ export default (reactotron, options) => {
// start a relative timer
const timer = reactotron.startTimer()

// ---------------- Sending Effect Updates ----------------
const sendReactotronEffectTree = () => reactotron.send('saga.effect.update', effects)

// ---------------- Starting -----------------------------

// redux-saga calls this when an effect is triggered (started)
Expand All @@ -39,6 +42,9 @@ export default (reactotron, options) => {

// store it
effects[effectId] = effectInfo

// send it
sendReactotronEffectTree()
}

// ---------------- Finishing ----------------------------
Expand Down Expand Up @@ -138,6 +144,8 @@ export default (reactotron, options) => {
duration: Math.round(duration),
children
})

effects = omit(map(String, pluck('effectId', children)), effects)
}

// redux-saga calls this when an effect is resolved (successfully or not)
Expand Down Expand Up @@ -178,6 +186,9 @@ export default (reactotron, options) => {
setRaceWinner(effectId, result)
}
}

// send it
sendReactotronEffectTree()
}

// flags on of the children as the winner
Expand Down Expand Up @@ -205,6 +216,9 @@ export default (reactotron, options) => {
if (effectInfo.name === RACE) {
setRaceWinner(effectId, error)
}

// send it
sendReactotronEffectTree()
}

// ---------------- Cancelling ---------------------------
Expand All @@ -214,6 +228,9 @@ export default (reactotron, options) => {
const effectInfo = effects[effectId]
updateDuration(effectInfo)
effectInfo.status = CANCELLED

// send it
sendReactotronEffectTree()
}

// the interface for becoming a redux-saga monitor
Expand Down