浏览代码

[flow] Take advantage of flow-typed

j8
Lyubomir Marinov 8 年前
父节点
当前提交
5de1a74429

+ 7
- 1
.eslintrc.js 查看文件

4
         'commonjs': true,
4
         'commonjs': true,
5
         'es6': true
5
         'es6': true
6
     },
6
     },
7
-    'extends': 'eslint:recommended',
7
+    'extends': [
8
+        'eslint:recommended',
9
+        'plugin:flowtype/recommended'
10
+    ],
8
     'globals': {
11
     'globals': {
9
         // The globals that (1) are accessed but not defined within many of our
12
         // The globals that (1) are accessed but not defined within many of our
10
         // files, (2) are certainly defined, and (3) we would like to use
13
         // files, (2) are certainly defined, and (3) we would like to use
19
         },
22
         },
20
         'sourceType': 'module'
23
         'sourceType': 'module'
21
     },
24
     },
25
+    'plugins': [
26
+        'flowtype'
27
+    ],
22
     'rules': {
28
     'rules': {
23
         'new-cap': [
29
         'new-cap': [
24
             'error',
30
             'error',

+ 1
- 0
package.json 查看文件

60
     "clean-css": "^3.0.0",
60
     "clean-css": "^3.0.0",
61
     "css-loader": "*",
61
     "css-loader": "*",
62
     "eslint": "^3.14.1",
62
     "eslint": "^3.14.1",
63
+    "eslint-plugin-flowtype": "^2.30.0",
63
     "eslint-plugin-import": "^2.2.0",
64
     "eslint-plugin-import": "^2.2.0",
64
     "eslint-plugin-jsdoc": "*",
65
     "eslint-plugin-jsdoc": "*",
65
     "eslint-plugin-react": "*",
66
     "eslint-plugin-react": "*",

+ 11
- 7
react/features/base/connection/actions.native.js 查看文件

1
+/* @flow */
2
+
3
+import type { Dispatch } from 'redux';
4
+
1
 import { conferenceWillLeave } from '../conference';
5
 import { conferenceWillLeave } from '../conference';
2
 import JitsiMeetJS from '../lib-jitsi-meet';
6
 import JitsiMeetJS from '../lib-jitsi-meet';
3
 
7
 
14
 /**
18
 /**
15
  * Opens new connection.
19
  * Opens new connection.
16
  *
20
  *
17
- * @returns {Promise<JitsiConnection>}
21
+ * @returns {Function}
18
  */
22
  */
19
 export function connect() {
23
 export function connect() {
20
-    return (dispatch, getState) => {
24
+    return (dispatch: Dispatch<*>, getState: Function) => {
21
         const state = getState();
25
         const state = getState();
22
         const connectionOptions
26
         const connectionOptions
23
             = state['features/base/connection'].connectionOptions;
27
             = state['features/base/connection'].connectionOptions;
57
          * @param {string} message - Disconnect reason.
61
          * @param {string} message - Disconnect reason.
58
          * @returns {void}
62
          * @returns {void}
59
          */
63
          */
60
-        function connectionDisconnected(message) {
64
+        function connectionDisconnected(message: string) {
61
             connection.removeEventListener(
65
             connection.removeEventListener(
62
                     JitsiConnectionEvents.CONNECTION_DISCONNECTED,
66
                     JitsiConnectionEvents.CONNECTION_DISCONNECTED,
63
                     connectionDisconnected);
67
                     connectionDisconnected);
110
  * @returns {Function}
114
  * @returns {Function}
111
  */
115
  */
112
 export function disconnect() {
116
 export function disconnect() {
113
-    return (dispatch, getState) => {
117
+    return (dispatch: Dispatch<*>, getState: Function) => {
114
         const state = getState();
118
         const state = getState();
115
         const conference = state['features/base/conference'].conference;
119
         const conference = state['features/base/conference'].conference;
116
         const connection = state['features/base/connection'].connection;
120
         const connection = state['features/base/connection'].connection;
148
  *      domain: string
152
  *      domain: string
149
  *  }}
153
  *  }}
150
  */
154
  */
151
-export function setDomain(domain) {
155
+export function setDomain(domain: string) {
152
     return {
156
     return {
153
         type: SET_DOMAIN,
157
         type: SET_DOMAIN,
154
         domain
158
         domain
167
  *     message: string
171
  *     message: string
168
  * }}
172
  * }}
169
  */
173
  */
170
-function _connectionDisconnected(connection, message) {
174
+function _connectionDisconnected(connection, message: string) {
171
     return {
175
     return {
172
         type: CONNECTION_DISCONNECTED,
176
         type: CONNECTION_DISCONNECTED,
173
         connection,
177
         connection,
205
  *     error: string
209
  *     error: string
206
  * }}
210
  * }}
207
  */
211
  */
208
-function _connectionFailed(connection, error) {
212
+function _connectionFailed(connection, error: string) {
209
     return {
213
     return {
210
         type: CONNECTION_FAILED,
214
         type: CONNECTION_FAILED,
211
         connection,
215
         connection,

+ 8
- 3
react/features/base/connection/actions.web.js 查看文件

1
-/* global APP, JitsiMeetJS */
1
+/* @flow */
2
+
3
+import type { Dispatch } from 'redux';
2
 
4
 
3
 import UIEvents from '../../../../service/UI/UIEvents';
5
 import UIEvents from '../../../../service/UI/UIEvents';
4
 
6
 
5
 import { SET_DOMAIN } from './actionTypes';
7
 import { SET_DOMAIN } from './actionTypes';
6
 import './reducer';
8
 import './reducer';
7
 
9
 
10
+declare var APP: Object;
11
+declare var JitsiMeetJS: Object;
12
+
8
 const JitsiConferenceEvents = JitsiMeetJS.events.conference;
13
 const JitsiConferenceEvents = JitsiMeetJS.events.conference;
9
 const logger = require('jitsi-meet-logger').getLogger(__filename);
14
 const logger = require('jitsi-meet-logger').getLogger(__filename);
10
 
15
 
14
  * @returns {Promise<JitsiConnection>}
19
  * @returns {Promise<JitsiConnection>}
15
  */
20
  */
16
 export function connect() {
21
 export function connect() {
17
-    return (dispatch, getState) => {
22
+    return (dispatch: Dispatch<*>, getState: Function) => {
18
         const state = getState();
23
         const state = getState();
19
 
24
 
20
         // XXX Lib-jitsi-meet does not accept uppercase letters.
25
         // XXX Lib-jitsi-meet does not accept uppercase letters.
88
  *      domain: string
93
  *      domain: string
89
  *  }}
94
  *  }}
90
  */
95
  */
91
-export function setDomain(domain) {
96
+export function setDomain(domain: string) {
92
     return {
97
     return {
93
         type: SET_DOMAIN,
98
         type: SET_DOMAIN,
94
         domain
99
         domain

+ 10
- 6
react/features/base/media/actions.js 查看文件

1
+/* @flow */
2
+
3
+import type { Dispatch } from 'redux';
4
+
1
 import {
5
 import {
2
     SET_AUDIO_MUTED,
6
     SET_AUDIO_MUTED,
3
     SET_CAMERA_FACING_MODE,
7
     SET_CAMERA_FACING_MODE,
17
  *      muted: boolean
21
  *      muted: boolean
18
  *  }}
22
  *  }}
19
  */
23
  */
20
-export function setAudioMuted(muted) {
24
+export function setAudioMuted(muted: boolean) {
21
     return {
25
     return {
22
         type: SET_AUDIO_MUTED,
26
         type: SET_AUDIO_MUTED,
23
         muted
27
         muted
33
  *      cameraFacingMode: CAMERA_FACING_MODE
37
  *      cameraFacingMode: CAMERA_FACING_MODE
34
  *  }}
38
  *  }}
35
  */
39
  */
36
-export function setCameraFacingMode(cameraFacingMode) {
40
+export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) {
37
     return {
41
     return {
38
         type: SET_CAMERA_FACING_MODE,
42
         type: SET_CAMERA_FACING_MODE,
39
         cameraFacingMode
43
         cameraFacingMode
50
  *      muted: boolean
54
  *      muted: boolean
51
  *  }}
55
  *  }}
52
  */
56
  */
53
-export function setVideoMuted(muted) {
57
+export function setVideoMuted(muted: boolean) {
54
     return {
58
     return {
55
         type: SET_VIDEO_MUTED,
59
         type: SET_VIDEO_MUTED,
56
         muted
60
         muted
63
  * @returns {Function}
67
  * @returns {Function}
64
  */
68
  */
65
 export function toggleAudioMuted() {
69
 export function toggleAudioMuted() {
66
-    return (dispatch, getState) => {
70
+    return (dispatch: Dispatch<*>, getState: Function) => {
67
         const muted = getState()['features/base/media'].audio.muted;
71
         const muted = getState()['features/base/media'].audio.muted;
68
 
72
 
69
         return dispatch(setAudioMuted(!muted));
73
         return dispatch(setAudioMuted(!muted));
76
  * @returns {Function}
80
  * @returns {Function}
77
  */
81
  */
78
 export function toggleCameraFacingMode() {
82
 export function toggleCameraFacingMode() {
79
-    return (dispatch, getState) => {
83
+    return (dispatch: Dispatch<*>, getState: Function) => {
80
         let cameraFacingMode
84
         let cameraFacingMode
81
             = getState()['features/base/media'].video.facingMode;
85
             = getState()['features/base/media'].video.facingMode;
82
 
86
 
95
  * @returns {Function}
99
  * @returns {Function}
96
  */
100
  */
97
 export function toggleVideoMuted() {
101
 export function toggleVideoMuted() {
98
-    return (dispatch, getState) => {
102
+    return (dispatch: Dispatch<*>, getState: Function) => {
99
         const muted = getState()['features/base/media'].video.muted;
103
         const muted = getState()['features/base/media'].video.muted;
100
 
104
 
101
         return dispatch(setVideoMuted(!muted));
105
         return dispatch(setVideoMuted(!muted));

+ 6
- 1
react/features/base/react/functions.js 查看文件

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
+/* eslint-disable flowtype/space-before-type-colon */
4
+
3
 /**
5
 /**
4
  * Prevents further propagation of the events to be handler by a specific event
6
  * Prevents further propagation of the events to be handler by a specific event
5
  * handler/listener in the capturing and bubbling phases.
7
  * handler/listener in the capturing and bubbling phases.
11
  */
13
  */
12
 export function stopEventPropagation<T>(eventHandler: (ev: Event) => T)
14
 export function stopEventPropagation<T>(eventHandler: (ev: Event) => T)
13
         : (ev: Event) => T {
15
         : (ev: Event) => T {
14
-    return (ev: Event) => {
16
+
17
+/* eslint-enable flowtype/space-before-type-colon */
18
+
19
+    return (ev: Event): T => {
15
         const r = eventHandler(ev);
20
         const r = eventHandler(ev);
16
 
21
 
17
         // React Native does not propagate the press event so, for the sake of
22
         // React Native does not propagate the press event so, for the sake of

+ 17
- 3
react/features/base/redux/ReducerRegistry.js 查看文件

1
+/* @flow */
2
+
1
 import { combineReducers } from 'redux';
3
 import { combineReducers } from 'redux';
4
+import type { Reducer } from 'redux';
5
+
6
+/**
7
+ * The type of the dictionary/map which associates a reducer (function) with the
8
+ * name of he Redux state property managed by the reducer.
9
+ */
10
+declare type NameReducerMap<S, A> = { [name: string]: Reducer<S, A> };
2
 
11
 
3
 /**
12
 /**
4
  * A registry for Redux reducers, allowing features to register themselves
13
  * A registry for Redux reducers, allowing features to register themselves
5
  * without needing to create additional inter-feature dependencies.
14
  * without needing to create additional inter-feature dependencies.
6
  */
15
  */
7
 class ReducerRegistry {
16
 class ReducerRegistry {
17
+    _elements: NameReducerMap<*, *>;
18
+
8
     /**
19
     /**
9
      * Creates a ReducerRegistry instance.
20
      * Creates a ReducerRegistry instance.
10
      */
21
      */
12
         /**
23
         /**
13
          * The set of registered reducers, keyed based on the field each reducer
24
          * The set of registered reducers, keyed based on the field each reducer
14
          * will manage.
25
          * will manage.
26
+         *
27
+         * @private
28
+         * @type {NameReducerMap}
15
          */
29
          */
16
         this._elements = {};
30
         this._elements = {};
17
     }
31
     }
23
      * included (such as reducers from third-party modules).
37
      * included (such as reducers from third-party modules).
24
      * @returns {Function}
38
      * @returns {Function}
25
      */
39
      */
26
-    combineReducers(additional = {}) {
40
+    combineReducers(additional: NameReducerMap<*, *> = {}) {
27
         return combineReducers({
41
         return combineReducers({
28
             ...this._elements,
42
             ...this._elements,
29
             ...additional
43
             ...additional
37
      *
51
      *
38
      * @param {string} name - The field in the state object that will be managed
52
      * @param {string} name - The field in the state object that will be managed
39
      * by the provided reducer.
53
      * by the provided reducer.
40
-     * @param {Function} reducer - A Redux reducer.
54
+     * @param {Reducer} reducer - A Redux reducer.
41
      * @returns {void}
55
      * @returns {void}
42
      */
56
      */
43
-    register(name, reducer) {
57
+    register(name: string, reducer: Reducer<*, *>) {
44
         this._elements[name] = reducer;
58
         this._elements[name] = reducer;
45
     }
59
     }
46
 }
60
 }

正在加载...
取消
保存