forked from infinitered/ignite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OPEN_SCREEN action for Reactotron dispatches
- Loading branch information
1 parent
129c455
commit 2ea4865
Showing
5 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createActions } from 'reduxsauce' | ||
|
||
/* ------------- Types and Action Creators ------------- */ | ||
|
||
const { Types, Creators } = createActions({ | ||
openScreen: ['screen', 'options'] | ||
}) | ||
|
||
export const OpenScreenTypes = Types | ||
export default Creators |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { call } from 'redux-saga/effects' | ||
import { Actions as NavigationActions, ActionConst } from 'react-native-router-flux' | ||
import { merge } from 'ramda' | ||
|
||
// Process OPEN_SCREEN actions, intended for use with Reactotron to open a screen via a direct dispatch | ||
export function * openScreen (action) { | ||
const {screen, options} = action | ||
// Always reset the nav stack when opening a screen via Reactotron | ||
// You can override the RESET type in the options passed to the OPEN_SCREEN dispatch | ||
const mergedOptions = merge({type: ActionConst.RESET}, options) | ||
yield call(NavigationActions[screen], mergedOptions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import test from 'ava' | ||
import { call } from 'redux-saga/effects' | ||
import { openScreen } from '../../App/Sagas/OpenScreenSagas' | ||
import { Actions as NavigationActions, ActionConst } from 'react-native-router-flux' | ||
|
||
const stepper = (fn) => (mock) => fn.next(mock).value | ||
|
||
// Using 'myScreen' in the mocks of the arguments passed to the action for these tests is important. | ||
// The react-native-router-flux component is mocked in App/Tests/Setup.js to use 'myScreen' | ||
|
||
test('the right default options are passed to the navigation action', (t) => { | ||
const mock = {screen: 'myScreen'} | ||
const step = stepper(openScreen(mock)) | ||
t.deepEqual(step(), call(NavigationActions['myScreen'], {type: ActionConst.RESET})) | ||
}) | ||
|
||
test('the right merged options are passed to the navigation action', (t) => { | ||
const mock = {screen: 'myScreen', options: {type: 'replace', foo: 'bar'}} | ||
const step = stepper(openScreen(mock)) | ||
t.deepEqual(step(), call(NavigationActions['myScreen'], {type: 'replace', foo: 'bar'})) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters