Skip to content

Commit 4c3aaa0

Browse files
committed
eventActions: Mark some more array params read-only, etc.
This is certainly our intent; and it prevents Flow from worrying about unsound use of mutability, once we tell Flow enough about these action types that it can know enough to get worried. Background explanation: Flow needs to know that there aren't two pieces of code X and Y and a shared mutable value V where (a) X might mutate V, (b) Y might read V, and (c) the type X sees V as is not a subtype of (nor the same as) how Y sees V. When X is a function that Y is calling, and V is an argument Y is passing in, that's what `$ReadOnlyArray<...>` etc. are for -- they guarantee X won't mutate V, so (a) doesn't apply and we're safe. That's what we do in 2 of the 3 spots in this commit. But here we also have the *return value* of `responseToActions` playing the role of V -- the function is Y, and its *caller* is X. Flow worries that the returned data might also be visible somewhere else that's depending on the data staying specifically `EventAction`, and the caller could mutate it to be other kinds of `Action`. Here I'm not so sure how to write down the immutability guarantee, so instead just call these values `Action`.
1 parent ff515bc commit 4c3aaa0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/actionCreator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Action, GlobalState, Dispatch } from './types';
33
import { clearTypingNotification } from './typing/clearTypingNotification';
44
import { EVENT_TYPING_START } from './actionConstants';
55

6-
export default (dispatch: Dispatch, actions: Action[], state: GlobalState) => {
6+
export default (dispatch: Dispatch, actions: $ReadOnlyArray<Action>, state: GlobalState) => {
77
actions.forEach(action => {
88
switch (action.type) {
99
case EVENT_TYPING_START:

src/events/eventActions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22
import { batchActions } from 'redux-batched-actions';
33

4-
import type { EventAction, Dispatch, GetState, GlobalState } from '../types';
4+
import type { Action, Dispatch, GetState, GlobalState } from '../types';
55
import { pollForEvents } from '../api';
66
import { deadQueue } from '../session/sessionActions';
77
import eventToAction from './eventToAction';
@@ -10,7 +10,7 @@ import { getAuth } from '../selectors';
1010
import actionCreator from '../actionCreator';
1111
import progressiveTimeout from '../utils/progressiveTimeout';
1212

13-
export const responseToActions = (state: GlobalState, response: Object): EventAction[] =>
13+
export const responseToActions = (state: GlobalState, response: Object): Action[] =>
1414
response.events
1515
.map(event => {
1616
eventMiddleware(state, event);
@@ -29,7 +29,7 @@ export const responseToActions = (state: GlobalState, response: Object): EventAc
2929
return true;
3030
});
3131

32-
export const dispatchOrBatch = (dispatch: Dispatch, actions: EventAction[]) => {
32+
export const dispatchOrBatch = (dispatch: Dispatch, actions: $ReadOnlyArray<Action>) => {
3333
if (actions.length > 1) {
3434
dispatch(batchActions(actions));
3535
} else if (actions.length === 1) {

0 commit comments

Comments
 (0)