Files
react-navigation/src/NavigationActions.js
Mike Grabowski bbe9caff06 Fix eslint issues and turn on prettier by default (#1195)
* Automatically generate prop-types from Flow

* Remove propTypes usage

* Fix flow

* Modify some eslint settings

* Fix flowtype

* Lint tweaks

* use prop-types pkg

* Run prettier

* Fix flow

* Fix few lint issues

* Make eslint pass

* Run lint on tests

* Fix flow

* Fixes

* Alphabetical

* Trailing comma: ES5 for website compat, also fix config/paths

* Apply eslint --fix only to src now

* Fix missing transitionconfig

* Update TypeDefinition.js

* New stuff

* Unstage website and examples

* reformat code

* Update circle.yml
2017-04-24 17:31:22 +05:30

76 lines
1.7 KiB
JavaScript

const namespacedAction = (action: string) => `Navigation/${action}`;
const BACK = namespacedAction('BACK');
const INIT = namespacedAction('INIT');
const NAVIGATE = namespacedAction('NAVIGATE');
const RESET = namespacedAction('RESET');
const SET_PARAMS = namespacedAction('SET_PARAMS');
const URI = namespacedAction('URI');
const createAction = (type: string) =>
(payload: Object = {}) => ({
type,
...payload,
});
const back = createAction(BACK);
const init = createAction(INIT);
const navigate = createAction(NAVIGATE);
const reset = createAction(RESET);
const setParams = createAction(SET_PARAMS);
const uri = createAction(URI);
const deprecatedActionMap = {
Back: BACK,
Init: INIT,
Navigate: NAVIGATE,
Reset: RESET,
SetParams: SET_PARAMS,
Uri: URI,
};
const mapDeprecatedActionAndWarn = (action: Object) => {
const mappedType = deprecatedActionMap[action.type];
if (!mappedType) {
return action;
}
console.warn(
[
`The action type '${action.type}' has been renamed to '${mappedType}'.`,
`'${action.type}' will continue to work while in beta but will be removed`,
'in the first major release. Moving forward, you should use the',
'action constants and action creators exported by this library in',
"the 'actions' object.",
'See https://github.com/react-community/react-navigation/pull/120 for',
'more details.',
].join(' '),
);
return {
...action,
type: deprecatedActionMap[action.type],
};
};
export default {
// Action constants
BACK,
INIT,
NAVIGATE,
RESET,
SET_PARAMS,
URI,
// Action creators
back,
init,
navigate,
reset,
setParams,
uri,
// TODO: Remove once old actions are deprecated
mapDeprecatedActionAndWarn,
};