浏览代码

[flow] Take advantage of flow-typed

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

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

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

+ 1
- 0
package.json 查看文件

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

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

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

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

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

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

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

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

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

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

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

正在加载...
取消
保存