我正在尝试学习React Native,我正在研究Native Starter Kit中的代码。我无法理解以下代码。我理解函数调用后的冒号通常是TypeScript的静态类型检查器的类型定义,因为我在Angular项目中使用它,但据我所知,启动项目不使用类似的东西。
类型文件:
export type Action =
{ type: 'PUSH_NEW_ROUTE', route: string }
| { type: 'POP_ROUTE' }
| { type: 'POP_TO_ROUTE', route: string }
| { type: 'REPLACE_ROUTE', route: string }
| { type: 'REPLACE_OR_PUSH_ROUTE', route: string }
| { type: 'OPEN_DRAWER'}
| { type: 'CLOSE_DRAWER'}
| { type: 'SET_USER', name: string}
| { type: 'SET_LIST', list: string}
export type Dispatch = (action:Action | Array<Action>) => any;
export type GetState = () => Object;
export type PromiseAction = Promise<Action>;
使用案例:
import type { Action } from './types';
export const SET_USER = 'SET_USER';
export function setUser(user:string):Action {
return {
type: SET_USER,
payload: user,
};
}
https://github.com/start-react/native-starter-kit
package.json文件:
{
"name": "NativeStarterKit",
"version": "6.1.0",
"private": true,
"scripts": {
"postinstall": "remotedev-debugger",
"start": "node_modules/react-native/packager/packager.sh",
"eslint": "eslint",
"test": "jest"
},
"dependencies": {
"color": "^0.11.3",
"lodash": "^4.13.1",
"moment": "^2.13.0",
"native-base": "2.1.1",
"react": "16.0.0-alpha.3",
"react-native": "0.43.1",
"react-native-code-push": "2.0.1-beta",
"react-native-easy-grid": "0.1.8",
"react-native-modalbox": "^1.3.4",
"react-native-router-flux": "3.38.0",
"react-redux": "^5.0.2",
"redux": "^3.6.0",
"redux-persist": "^4.0.0",
"redux-thunk": "^2.2.0",
"remote-redux-devtools": "^0.5.0"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
"babel-jest": "17.0.0",
"babel-preset-react-native": "1.9.0",
"chai": "^3.5.0",
"eslint": "^3.5.0",
"eslint-config-airbnb": "^11.1.0",
"eslint-plugin-import": "^1.14.0",
"eslint-plugin-jsx-a11y": "^2.2.1",
"eslint-plugin-react": "^6.2.0",
"eslint-plugin-react-native": "^2.0.0",
"jest": "17.0.0",
"jest-react-native": "17.0.0",
"mocha": "^2.5.3",
"react-test-renderer": "15.3.2",
"remote-redux-devtools-on-debugger": "^0.7.0",
"remotedev-server": "^0.1.2"
},
"keywords": [
"android",
"ios",
"react",
"native",
"react-native",
"native-base",
"native-modules",
"react-component",
"navbar",
"packager",
"rnpm",
"es6",
"redux",
"react-native-code-push",
"react-native boilerplate",
"react-native with redux",
"react-native with redux boilerplate",
"native-base boilerplate",
"react-native with native-base"
],
"upstreamRepo": "git@github.com:GeekyAnts/react-native-native-base-seed.git",
"jest": {
"preset": "jest-react-native"
}
}
感谢。