From 5de1a744294274a34710134aced93823ef5b8ded Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Fri, 3 Feb 2017 12:50:06 -0600 Subject: [PATCH] [flow] Take advantage of flow-typed --- .eslintrc.js | 8 +++++++- package.json | 1 + .../base/connection/actions.native.js | 18 ++++++++++------- react/features/base/connection/actions.web.js | 11 +++++++--- react/features/base/media/actions.js | 16 +++++++++------ react/features/base/react/functions.js | 7 ++++++- react/features/base/redux/ReducerRegistry.js | 20 ++++++++++++++++--- 7 files changed, 60 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2b9397679..64947373a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,7 +4,10 @@ module.exports = { 'commonjs': true, 'es6': true }, - 'extends': 'eslint:recommended', + 'extends': [ + 'eslint:recommended', + 'plugin:flowtype/recommended' + ], 'globals': { // The globals that (1) are accessed but not defined within many of our // files, (2) are certainly defined, and (3) we would like to use @@ -19,6 +22,9 @@ module.exports = { }, 'sourceType': 'module' }, + 'plugins': [ + 'flowtype' + ], 'rules': { 'new-cap': [ 'error', diff --git a/package.json b/package.json index dd9f61bf4..32de0f2e6 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "clean-css": "^3.0.0", "css-loader": "*", "eslint": "^3.14.1", + "eslint-plugin-flowtype": "^2.30.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsdoc": "*", "eslint-plugin-react": "*", diff --git a/react/features/base/connection/actions.native.js b/react/features/base/connection/actions.native.js index 329b2e6d4..77f8671b2 100644 --- a/react/features/base/connection/actions.native.js +++ b/react/features/base/connection/actions.native.js @@ -1,3 +1,7 @@ +/* @flow */ + +import type { Dispatch } from 'redux'; + import { conferenceWillLeave } from '../conference'; import JitsiMeetJS from '../lib-jitsi-meet'; @@ -14,10 +18,10 @@ const JitsiConnectionEvents = JitsiMeetJS.events.connection; /** * Opens new connection. * - * @returns {Promise} + * @returns {Function} */ export function connect() { - return (dispatch, getState) => { + return (dispatch: Dispatch<*>, getState: Function) => { const state = getState(); const connectionOptions = state['features/base/connection'].connectionOptions; @@ -57,7 +61,7 @@ export function connect() { * @param {string} message - Disconnect reason. * @returns {void} */ - function connectionDisconnected(message) { + function connectionDisconnected(message: string) { connection.removeEventListener( JitsiConnectionEvents.CONNECTION_DISCONNECTED, connectionDisconnected); @@ -110,7 +114,7 @@ export function connect() { * @returns {Function} */ export function disconnect() { - return (dispatch, getState) => { + return (dispatch: Dispatch<*>, getState: Function) => { const state = getState(); const conference = state['features/base/conference'].conference; const connection = state['features/base/connection'].connection; @@ -148,7 +152,7 @@ export function disconnect() { * domain: string * }} */ -export function setDomain(domain) { +export function setDomain(domain: string) { return { type: SET_DOMAIN, domain @@ -167,7 +171,7 @@ export function setDomain(domain) { * message: string * }} */ -function _connectionDisconnected(connection, message) { +function _connectionDisconnected(connection, message: string) { return { type: CONNECTION_DISCONNECTED, connection, @@ -205,7 +209,7 @@ function _connectionEstablished(connection) { * error: string * }} */ -function _connectionFailed(connection, error) { +function _connectionFailed(connection, error: string) { return { type: CONNECTION_FAILED, connection, diff --git a/react/features/base/connection/actions.web.js b/react/features/base/connection/actions.web.js index dc432eac2..c1b44589e 100644 --- a/react/features/base/connection/actions.web.js +++ b/react/features/base/connection/actions.web.js @@ -1,10 +1,15 @@ -/* global APP, JitsiMeetJS */ +/* @flow */ + +import type { Dispatch } from 'redux'; import UIEvents from '../../../../service/UI/UIEvents'; import { SET_DOMAIN } from './actionTypes'; import './reducer'; +declare var APP: Object; +declare var JitsiMeetJS: Object; + const JitsiConferenceEvents = JitsiMeetJS.events.conference; const logger = require('jitsi-meet-logger').getLogger(__filename); @@ -14,7 +19,7 @@ const logger = require('jitsi-meet-logger').getLogger(__filename); * @returns {Promise} */ export function connect() { - return (dispatch, getState) => { + return (dispatch: Dispatch<*>, getState: Function) => { const state = getState(); // XXX Lib-jitsi-meet does not accept uppercase letters. @@ -88,7 +93,7 @@ export function disconnect() { * domain: string * }} */ -export function setDomain(domain) { +export function setDomain(domain: string) { return { type: SET_DOMAIN, domain diff --git a/react/features/base/media/actions.js b/react/features/base/media/actions.js index c3e38baa6..cbd9222ff 100644 --- a/react/features/base/media/actions.js +++ b/react/features/base/media/actions.js @@ -1,3 +1,7 @@ +/* @flow */ + +import type { Dispatch } from 'redux'; + import { SET_AUDIO_MUTED, SET_CAMERA_FACING_MODE, @@ -17,7 +21,7 @@ import './reducer'; * muted: boolean * }} */ -export function setAudioMuted(muted) { +export function setAudioMuted(muted: boolean) { return { type: SET_AUDIO_MUTED, muted @@ -33,7 +37,7 @@ export function setAudioMuted(muted) { * cameraFacingMode: CAMERA_FACING_MODE * }} */ -export function setCameraFacingMode(cameraFacingMode) { +export function setCameraFacingMode(cameraFacingMode: CAMERA_FACING_MODE) { return { type: SET_CAMERA_FACING_MODE, cameraFacingMode @@ -50,7 +54,7 @@ export function setCameraFacingMode(cameraFacingMode) { * muted: boolean * }} */ -export function setVideoMuted(muted) { +export function setVideoMuted(muted: boolean) { return { type: SET_VIDEO_MUTED, muted @@ -63,7 +67,7 @@ export function setVideoMuted(muted) { * @returns {Function} */ export function toggleAudioMuted() { - return (dispatch, getState) => { + return (dispatch: Dispatch<*>, getState: Function) => { const muted = getState()['features/base/media'].audio.muted; return dispatch(setAudioMuted(!muted)); @@ -76,7 +80,7 @@ export function toggleAudioMuted() { * @returns {Function} */ export function toggleCameraFacingMode() { - return (dispatch, getState) => { + return (dispatch: Dispatch<*>, getState: Function) => { let cameraFacingMode = getState()['features/base/media'].video.facingMode; @@ -95,7 +99,7 @@ export function toggleCameraFacingMode() { * @returns {Function} */ export function toggleVideoMuted() { - return (dispatch, getState) => { + return (dispatch: Dispatch<*>, getState: Function) => { const muted = getState()['features/base/media'].video.muted; return dispatch(setVideoMuted(!muted)); diff --git a/react/features/base/react/functions.js b/react/features/base/react/functions.js index 457418d6e..9b0f163e7 100644 --- a/react/features/base/react/functions.js +++ b/react/features/base/react/functions.js @@ -1,5 +1,7 @@ /* @flow */ +/* eslint-disable flowtype/space-before-type-colon */ + /** * Prevents further propagation of the events to be handler by a specific event * handler/listener in the capturing and bubbling phases. @@ -11,7 +13,10 @@ */ export function stopEventPropagation(eventHandler: (ev: Event) => T) : (ev: Event) => T { - return (ev: Event) => { + +/* eslint-enable flowtype/space-before-type-colon */ + + return (ev: Event): T => { const r = eventHandler(ev); // React Native does not propagate the press event so, for the sake of diff --git a/react/features/base/redux/ReducerRegistry.js b/react/features/base/redux/ReducerRegistry.js index 4e9563cf7..18628f5bd 100644 --- a/react/features/base/redux/ReducerRegistry.js +++ b/react/features/base/redux/ReducerRegistry.js @@ -1,10 +1,21 @@ +/* @flow */ + import { combineReducers } from 'redux'; +import type { Reducer } from 'redux'; + +/** + * The type of the dictionary/map which associates a reducer (function) with the + * name of he Redux state property managed by the reducer. + */ +declare type NameReducerMap = { [name: string]: Reducer }; /** * A registry for Redux reducers, allowing features to register themselves * without needing to create additional inter-feature dependencies. */ class ReducerRegistry { + _elements: NameReducerMap<*, *>; + /** * Creates a ReducerRegistry instance. */ @@ -12,6 +23,9 @@ class ReducerRegistry { /** * The set of registered reducers, keyed based on the field each reducer * will manage. + * + * @private + * @type {NameReducerMap} */ this._elements = {}; } @@ -23,7 +37,7 @@ class ReducerRegistry { * included (such as reducers from third-party modules). * @returns {Function} */ - combineReducers(additional = {}) { + combineReducers(additional: NameReducerMap<*, *> = {}) { return combineReducers({ ...this._elements, ...additional @@ -37,10 +51,10 @@ class ReducerRegistry { * * @param {string} name - The field in the state object that will be managed * by the provided reducer. - * @param {Function} reducer - A Redux reducer. + * @param {Reducer} reducer - A Redux reducer. * @returns {void} */ - register(name, reducer) { + register(name: string, reducer: Reducer<*, *>) { this._elements[name] = reducer; } }