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

Adds a guard for root-level forked tasks. #258

Merged
merged 2 commits into from
Nov 15, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/demo-react-js/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class App extends Component {
)
}

componentDidMount () {
this.props.startup()
}

renderMessage () {
const { fetching, name, url, message, sha } = this.props
if (fetching) {
Expand Down
5 changes: 2 additions & 3 deletions packages/demo-react-js/src/Sagas/Startup.sagas.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// import { put } from 'redux-saga/effects'
// import * as RepoMessage from '../Redux/RepoMessage.redux'
import { put } from 'redux-saga/effects'

// process STARTUP actions
export function * startup () {
// yield put(RepoMessage.Actions.request())
yield put({ type: 'HELLO' })
}
6 changes: 6 additions & 0 deletions packages/demo-react-js/src/Sagas/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { takeEvery, takeLatest } from 'redux-saga'
import { fork, call } from 'redux-saga/effects'
import ApiSauce from 'apisauce'
const Reactotron = process.env.NODE_ENV !== 'production' && require('reactotron-react-js').default

Expand All @@ -19,7 +20,12 @@ if (process.env.NODE_ENV !== 'production') {
api.addMonitor(Reactotron.apisauce)
}

function * hi (name) {
yield call(console.log, name)
}

export default function * rootSaga () {
yield fork(hi, 'programmer!')
yield [
takeLatest(Repo.Types.Request, requestRepo, api),
takeEvery(Startup.Types.Startup, startup)
Expand Down
6 changes: 6 additions & 0 deletions packages/demo-react-native/App/Containers/RootContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Button from '../Components/Button'
import Repo from '../Components/Repo'
import { Actions as RepoActions } from '../Redux/RepoRedux'
import { Actions as LogoActions } from '../Redux/LogoRedux'
import { Actions as StartupActions } from '../Redux/StartupRedux'
import makeErrorForFun from '../Lib/ErrorMaker'
import RNViewShot from 'react-native-view-shot'

Expand All @@ -26,6 +27,10 @@ class RootContainer extends Component {
console.tron.log('A touchable was pressed.🔥🦄')
}

componentDidMount () {
this.props.startup()
}

handleSendCatPicture () {
this.props.ignore()
console.tron.image({
Expand Down Expand Up @@ -90,6 +95,7 @@ const mapStateToProps = (state) => {
}

const mapDispatchToProps = dispatch => ({
startup: () => dispatch(StartupActions.startup()),
ignore: () => dispatch({ type: 'ignore' }),
faster: () => dispatch(LogoActions.changeSpeed(10)),
slower: () => dispatch(LogoActions.changeSpeed(50)),
Expand Down
5 changes: 2 additions & 3 deletions packages/demo-react-native/App/Sagas/StartupSagas.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// import { put } from 'redux-saga/effects'
// import * as RepoMessage from '../Redux/RepoMessage.redux'
import { put } from 'redux-saga/effects'

// process STARTUP actions
export function * startup () {
// yield put(RepoMessage.Actions.request())
yield put({ type: 'HELLO' })
}
4 changes: 2 additions & 2 deletions packages/demo-react-native/App/Sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ api.addMonitor(Reactotron.apisauce)

export default function * rootSaga () {
yield [
takeLatest(Repo.Types.Request, requestRepo, api),
takeEvery(Startup.Types.Startup, startup)
takeEvery(Startup.Types.Startup, startup),
takeLatest(Repo.Types.Request, requestRepo, api)
]
}
28 changes: 16 additions & 12 deletions packages/reactotron-redux-saga/src/saga-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,34 @@ export default (reactotron, options) => {
}

// fires when a task has been resolved
// TODO: this is the only thing i'm interested in right now. it's really
// a subset of what can be tracked by redux-saga, but my head hurts trying
// to follow all the cases.
//
// I'd like figure out just how to display saga information, and that's really
// what is holding me back from deciding what to throw over the wire to reactotron.
const taskResolved = (effectId, taskResult) => {
// lookup this effect info
const effectInfo = effects[effectId]
updateDuration(effectInfo)
const { duration } = effectInfo

// grab the parent too
const { parentEffectId } = effectInfo
const parentEffectInfo = effects[parentEffectId]
const children = []
const sample = {}

// a human friendly name of the saga task
let sagaDescription
const { duration } = effectInfo
// what caused the trigger
let triggerType

// for FORK tasks, we have a bunch on things to pass along
if (effectInfo.name === FORK) {
const args = pathOr([], split('.', 'effect.FORK.args'), effectInfo)
const lastArg = last(args)
sample.type = lastArg && lastArg.type
if (parentEffectInfo.name === ITERATOR) {
sagaDescription = parentEffectInfo.description
triggerType = lastArg && lastArg.type
if (parentEffectInfo) {
if (parentEffectInfo.name === ITERATOR) {
sagaDescription = parentEffectInfo.description
}
} else {
sagaDescription = '(root)'
triggerType = `${effectInfo.description}()`
}

// flatten out the nested effects
Expand Down Expand Up @@ -129,7 +133,7 @@ export default (reactotron, options) => {
}

reactotron.send('saga.task.complete', {
triggerType: sample.type,
triggerType,
description: sagaDescription,
duration: Math.round(duration),
children
Expand Down