[flow] Take advantage of flow-typed

This commit is contained in:
Lyubomir Marinov 2017-02-03 12:50:06 -06:00 committed by hristoterezov
parent 2063ad467d
commit 5de1a74429
7 changed files with 60 additions and 21 deletions

View File

@ -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',

View File

@ -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": "*",

View File

@ -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<JitsiConnection>}
* @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,

View File

@ -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<JitsiConnection>}
*/
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

View File

@ -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));

View File

@ -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<T>(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

View File

@ -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<S, A> = { [name: string]: Reducer<S, A> };
/**
* 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;
}
}