mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-11 23:58:31 +08:00
Remove flow (#3350)
* Remove flow types from src * Finish removing Flow * Clear out flow-typed, some flow mentions in docs, website flow usage, and some other config
This commit is contained in:
committed by
Eric Vicenti
parent
276249c4c7
commit
ecfa38bfd2
@@ -1,20 +1,3 @@
|
||||
/**
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {
|
||||
NavigationAction,
|
||||
PossiblyDeprecatedNavigationAction,
|
||||
DeprecatedNavigationNavigateAction,
|
||||
NavigationInitAction,
|
||||
NavigationNavigateAction,
|
||||
NavigationBackAction,
|
||||
NavigationSetParamsAction,
|
||||
NavigationResetAction,
|
||||
NavigationUriAction,
|
||||
NavigationParams,
|
||||
} from './TypeDefinition';
|
||||
|
||||
const BACK = 'Navigation/BACK';
|
||||
const INIT = 'Navigation/INIT';
|
||||
const NAVIGATE = 'Navigation/NAVIGATE';
|
||||
@@ -22,87 +5,61 @@ const RESET = 'Navigation/RESET';
|
||||
const SET_PARAMS = 'Navigation/SET_PARAMS';
|
||||
const URI = 'Navigation/URI';
|
||||
|
||||
const createAction = (type: string, fn: any) => {
|
||||
const createAction = (type, fn) => {
|
||||
fn.toString = () => type;
|
||||
return fn;
|
||||
};
|
||||
|
||||
const back = createAction(
|
||||
BACK,
|
||||
(payload: { key?: ?string } = {}): NavigationBackAction => ({
|
||||
type: BACK,
|
||||
key: payload.key,
|
||||
})
|
||||
);
|
||||
const init = createAction(
|
||||
INIT,
|
||||
(payload: { params?: NavigationParams } = {}): NavigationInitAction => {
|
||||
const action: NavigationInitAction = {
|
||||
type: INIT,
|
||||
};
|
||||
if (payload.params) {
|
||||
action.params = payload.params;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
);
|
||||
const navigate = createAction(
|
||||
NAVIGATE,
|
||||
(payload: {
|
||||
routeName: string,
|
||||
params?: ?NavigationParams,
|
||||
action?: ?NavigationNavigateAction,
|
||||
}): NavigationNavigateAction => {
|
||||
const action: NavigationNavigateAction = {
|
||||
type: NAVIGATE,
|
||||
routeName: payload.routeName,
|
||||
};
|
||||
if (payload.params) {
|
||||
action.params = payload.params;
|
||||
}
|
||||
if (payload.action) {
|
||||
action.action = payload.action;
|
||||
}
|
||||
return action;
|
||||
}
|
||||
);
|
||||
const reset = createAction(
|
||||
RESET,
|
||||
(payload: {
|
||||
index: number,
|
||||
key?: ?string,
|
||||
actions: Array<NavigationNavigateAction>,
|
||||
}): NavigationResetAction => ({
|
||||
type: RESET,
|
||||
index: payload.index,
|
||||
key: payload.key,
|
||||
actions: payload.actions,
|
||||
})
|
||||
);
|
||||
const setParams = createAction(
|
||||
SET_PARAMS,
|
||||
(payload: {
|
||||
key: string,
|
||||
params: NavigationParams,
|
||||
}): NavigationSetParamsAction => ({
|
||||
type: SET_PARAMS,
|
||||
key: payload.key,
|
||||
params: payload.params,
|
||||
})
|
||||
);
|
||||
const uri = createAction(
|
||||
URI,
|
||||
(payload: { uri: string }): NavigationUriAction => ({
|
||||
type: URI,
|
||||
uri: payload.uri,
|
||||
})
|
||||
);
|
||||
const back = createAction(BACK, (payload = {}) => ({
|
||||
type: BACK,
|
||||
key: payload.key,
|
||||
}));
|
||||
|
||||
const mapDeprecatedNavigateAction = (
|
||||
action: NavigationNavigateAction | DeprecatedNavigationNavigateAction
|
||||
): NavigationNavigateAction => {
|
||||
const init = createAction(INIT, (payload = {}) => {
|
||||
const action = {
|
||||
type: INIT,
|
||||
};
|
||||
if (payload.params) {
|
||||
action.params = payload.params;
|
||||
}
|
||||
return action;
|
||||
});
|
||||
|
||||
const navigate = createAction(NAVIGATE, payload => {
|
||||
const action = {
|
||||
type: NAVIGATE,
|
||||
routeName: payload.routeName,
|
||||
};
|
||||
if (payload.params) {
|
||||
action.params = payload.params;
|
||||
}
|
||||
if (payload.action) {
|
||||
action.action = payload.action;
|
||||
}
|
||||
return action;
|
||||
});
|
||||
|
||||
const reset = createAction(RESET, payload => ({
|
||||
type: RESET,
|
||||
index: payload.index,
|
||||
key: payload.key,
|
||||
actions: payload.actions,
|
||||
}));
|
||||
|
||||
const setParams = createAction(SET_PARAMS, payload => ({
|
||||
type: SET_PARAMS,
|
||||
key: payload.key,
|
||||
params: payload.params,
|
||||
}));
|
||||
|
||||
const uri = createAction(URI, payload => ({
|
||||
type: URI,
|
||||
uri: payload.uri,
|
||||
}));
|
||||
|
||||
const mapDeprecatedNavigateAction = action => {
|
||||
if (action.type === 'Navigate') {
|
||||
const payload: Object = {
|
||||
const payload = {
|
||||
routeName: action.routeName,
|
||||
params: action.params,
|
||||
};
|
||||
@@ -114,9 +71,7 @@ const mapDeprecatedNavigateAction = (
|
||||
return action;
|
||||
};
|
||||
|
||||
const mapDeprecatedAction = (
|
||||
action: PossiblyDeprecatedNavigationAction
|
||||
): NavigationAction => {
|
||||
const mapDeprecatedAction = action => {
|
||||
if (action.type === 'Back') {
|
||||
return back(action);
|
||||
} else if (action.type === 'Init') {
|
||||
@@ -135,9 +90,7 @@ const mapDeprecatedAction = (
|
||||
return action;
|
||||
};
|
||||
|
||||
const mapDeprecatedActionAndWarn = (
|
||||
action: PossiblyDeprecatedNavigationAction
|
||||
): NavigationAction => {
|
||||
const mapDeprecatedActionAndWarn = action => {
|
||||
const newAction = mapDeprecatedAction(action);
|
||||
if (newAction !== action) {
|
||||
const oldType = action.type;
|
||||
|
||||
Reference in New Issue
Block a user