Browse Source

[flow] Type annotations

master
Lyubomir Marinov 8 years ago
parent
commit
cfa3047330

+ 2
- 0
react/features/base/react/Platform.native.js View File

1
+/* @flow */
2
+
1
 // Re-export react-native's Platform because we want to provide a minimal
3
 // Re-export react-native's Platform because we want to provide a minimal
2
 // equivalent on Web.
4
 // equivalent on Web.
3
 import { Platform } from 'react-native';
5
 import { Platform } from 'react-native';

+ 2
- 0
react/features/base/react/Platform.web.js View File

1
+/* @flow */
2
+
1
 const userAgent = navigator.userAgent;
3
 const userAgent = navigator.userAgent;
2
 let OS;
4
 let OS;
3
 
5
 

+ 28
- 12
react/features/base/react/RouteRegistry.js View File

1
+/* @flow */
2
+
3
+import { Component } from 'react';
4
+
1
 /**
5
 /**
2
  * Object describing application route.
6
  * Object describing application route.
3
  *
7
  *
5
  * @property {Component} component - React Component constructor.
9
  * @property {Component} component - React Component constructor.
6
  * @property {string} path - URL route, required for web routing.
10
  * @property {string} path - URL route, required for web routing.
7
  */
11
  */
12
+type Route = {
13
+    component: Class<Component<*>>, // eslint-disable-line no-undef
14
+    path: string
15
+};
8
 
16
 
9
 /**
17
 /**
10
  * A registry for Navigator routes, allowing features to register themselves
18
  * A registry for Navigator routes, allowing features to register themselves
11
  * without needing to create additional inter-feature dependencies.
19
  * without needing to create additional inter-feature dependencies.
12
  */
20
  */
13
 class RouteRegistry {
21
 class RouteRegistry {
22
+    _elements: Route[];
23
+
14
     /**
24
     /**
15
      * Initializes a new RouteRegistry instance.
25
      * Initializes a new RouteRegistry instance.
16
      */
26
      */
19
          * The set of registered routes.
29
          * The set of registered routes.
20
          *
30
          *
21
          * @private
31
          * @private
32
+         * @type {Route[]}
22
          */
33
          */
23
-        this._elements = new Set();
34
+        this._elements = [];
24
     }
35
     }
25
 
36
 
26
     /**
37
     /**
32
      * @returns {boolean} True if the specified a and b describe one and the
43
      * @returns {boolean} True if the specified a and b describe one and the
33
      * same abstract route; otherwise, false.
44
      * same abstract route; otherwise, false.
34
      */
45
      */
35
-    areRoutesEqual(a, b) {
46
+    areRoutesEqual(a: Route, b: Route) {
36
         if (a === b) { // reflexive
47
         if (a === b) { // reflexive
37
             return true;
48
             return true;
38
         }
49
         }
60
         // We use the destructuring operator to 'clone' the route object to
71
         // We use the destructuring operator to 'clone' the route object to
61
         // prevent modifications from outside (e.g. React Native's Navigator
72
         // prevent modifications from outside (e.g. React Native's Navigator
62
         // extends it with additional properties).
73
         // extends it with additional properties).
63
-        return [ ...this._elements ].map(r => {
74
+        return this._elements.map(r => {
64
             return { ...r };
75
             return { ...r };
65
         });
76
         });
66
     }
77
     }
67
 
78
 
79
+/* eslint-disable no-undef */
80
+
68
     /**
81
     /**
69
      * Returns registered route by name if any.
82
      * Returns registered route by name if any.
70
      *
83
      *
71
-     * @param {Object} component - The React Component (class) of the route to
72
-     * retrieve.
84
+     * @param {Component} component - The React Component (class) of the route
85
+     * to retrieve.
73
      * @returns {Route|null}
86
      * @returns {Route|null}
74
      */
87
      */
75
-    getRouteByComponent(component) {
76
-        const route
77
-            = [ ...this._elements ].find(r => r.component === component);
88
+    getRouteByComponent(component: Class<Component<*>>) {
89
+
90
+/* eslint-enable no-undef */
91
+
92
+        const route = this._elements.find(r => r.component === component);
78
 
93
 
79
         // We use destructuring operator to 'clone' route object to prevent
94
         // We use destructuring operator to 'clone' route object to prevent
80
         // modifications from outside (e.g. React Native's Navigator extends
95
         // modifications from outside (e.g. React Native's Navigator extends
88
      * @param {Route} route - Route definition object.
103
      * @param {Route} route - Route definition object.
89
      * @returns {void}
104
      * @returns {void}
90
      */
105
      */
91
-    register(route) {
92
-        if (this._elements.has(route)) {
93
-            throw new Error(`Route ${route.component} is registered already!`);
106
+    register(route: Route) {
107
+        if (this._elements.includes(route)) {
108
+            throw new Error(
109
+                    `Route ${String(route.component)} is registered already!`);
94
         }
110
         }
95
 
111
 
96
-        this._elements.add(route);
112
+        this._elements.push(route);
97
     }
113
     }
98
 }
114
 }
99
 
115
 

+ 5
- 2
react/features/base/react/functions.js View File

1
+/* @flow */
2
+
1
 /**
3
 /**
2
  * Prevents further propagation of the events to be handler by a specific event
4
  * Prevents further propagation of the events to be handler by a specific event
3
  * handler/listener in the capturing and bubbling phases.
5
  * handler/listener in the capturing and bubbling phases.
7
  * @returns {Function} An event handler/listener to be used in place of the
9
  * @returns {Function} An event handler/listener to be used in place of the
8
  * specified eventHandler in order to stop the events from propagating.
10
  * specified eventHandler in order to stop the events from propagating.
9
  */
11
  */
10
-export function stopEventPropagation(eventHandler) {
11
-    return ev => {
12
+export function stopEventPropagation<T>(eventHandler: (ev: Event) => T)
13
+        : (ev: Event) => T {
14
+    return (ev: Event) => {
12
         const r = eventHandler(ev);
15
         const r = eventHandler(ev);
13
 
16
 
14
         // React Native does not propagate the press event so, for the sake of
17
         // React Native does not propagate the press event so, for the sake of

+ 16
- 7
react/features/base/redux/MiddlewareRegistry.js View File

1
+/* @flow */
2
+
1
 import { applyMiddleware } from 'redux';
3
 import { applyMiddleware } from 'redux';
2
 
4
 
5
+type Middleware = Function;
6
+
3
 /**
7
 /**
4
  * A registry for Redux middleware, allowing features to register their
8
  * A registry for Redux middleware, allowing features to register their
5
  * middleware without needing to create additional inter-feature dependencies.
9
  * middleware without needing to create additional inter-feature dependencies.
6
  */
10
  */
7
 class MiddlewareRegistry {
11
 class MiddlewareRegistry {
12
+    _elements: Middleware[];
13
+
8
     /**
14
     /**
9
      * Creates a MiddlewareRegistry instance.
15
      * Creates a MiddlewareRegistry instance.
10
      */
16
      */
11
     constructor() {
17
     constructor() {
12
         /**
18
         /**
13
          * The set of registered middleware.
19
          * The set of registered middleware.
20
+         *
21
+         * @private
22
+         * @type {Route[]}
14
          */
23
          */
15
-        this._elements = new Set();
24
+        this._elements = [];
16
     }
25
     }
17
 
26
 
18
     /**
27
     /**
19
      * Applies all registered middleware into a store enhancer.
28
      * Applies all registered middleware into a store enhancer.
20
      * (@link http://redux.js.org/docs/api/applyMiddleware.html).
29
      * (@link http://redux.js.org/docs/api/applyMiddleware.html).
21
      *
30
      *
22
-     * @param {Function[]} additional - Any additional middleware that need to
31
+     * @param {Middleware[]} additional - Any additional middleware that need to
23
      * be included (such as middleware from third-party modules).
32
      * be included (such as middleware from third-party modules).
24
-     * @returns {Function}
33
+     * @returns {Middleware}
25
      */
34
      */
26
-    applyMiddleware(...additional) {
35
+    applyMiddleware(...additional: Middleware[]) {
27
         return applyMiddleware(
36
         return applyMiddleware(
28
             ...this._elements,
37
             ...this._elements,
29
             ...additional
38
             ...additional
35
      *
44
      *
36
      * The method is to be invoked only before {@link #applyMiddleware()}.
45
      * The method is to be invoked only before {@link #applyMiddleware()}.
37
      *
46
      *
38
-     * @param {Function} middleware - A Redux middleware.
47
+     * @param {Middleware} middleware - A Redux middleware.
39
      * @returns {void}
48
      * @returns {void}
40
      */
49
      */
41
-    register(middleware) {
42
-        this._elements.add(middleware);
50
+    register(middleware: Middleware) {
51
+        this._elements.push(middleware);
43
     }
52
     }
44
 }
53
 }
45
 
54
 

+ 1
- 1
react/features/base/util/randomUtil.js View File

30
  * @param {Array|string} arr - Source.
30
  * @param {Array|string} arr - Source.
31
  * @returns {Array|string} Array element or string character.
31
  * @returns {Array|string} Array element or string character.
32
  */
32
  */
33
-export function randomElement(arr: Array<any> | string) {
33
+export function randomElement(arr: [any] | string) {
34
     return arr[randomInt(0, arr.length - 1)];
34
     return arr[randomInt(0, arr.length - 1)];
35
 }
35
 }
36
 
36
 

Loading…
Cancel
Save