fbshipit-source-id: c71048dfea2a03cf83650b55aa9d1e463251920c

This commit is contained in:
Daniel Buchele
2018-07-04 07:19:44 -07:00
parent e6fa377d75
commit 5163f8b9a3
18 changed files with 235 additions and 247 deletions

View File

@@ -8,6 +8,7 @@
import {combineReducers} from 'redux';
import application from './application.js';
import connections from './connections.js';
import server from './server.js';
import pluginStates from './pluginStates.js';
import type {
State as ApplicationState,
@@ -21,6 +22,7 @@ import type {
State as PluginsState,
Action as PluginsAction,
} from './pluginStates.js';
import type {State as ServerState, Action as ServerAction} from './server.js';
import type {Store as ReduxStore} from 'redux';
export type Store = ReduxStore<
@@ -28,8 +30,14 @@ export type Store = ReduxStore<
application: ApplicationState,
connections: DevicesState,
pluginStates: PluginsState,
server: ServerState,
},
ApplicationAction | DevicesAction | PluginsAction,
ApplicationAction | DevicesAction | PluginsAction | ServerAction,
>;
export default combineReducers({application, connections, pluginStates});
export default combineReducers({
application,
connections,
pluginStates,
server,
});

54
src/reducers/server.js Normal file
View File

@@ -0,0 +1,54 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
export type State = {
error: ?string,
clients: Array<Client>,
};
export type Action =
| {
type: 'SERVER_ERROR',
payload: ?string,
}
| {
type: 'NEW_CLIENT',
payload: Client,
}
| {
type: 'CLIENT_REMOVED',
payload: string,
};
const INITIAL_STATE: State = {
error: null,
clients: [],
};
export default function reducer(
state: State = INITIAL_STATE,
action: Action,
): State {
if (action.type === 'NEW_CLIENT') {
const {payload} = action;
return {
...state,
clients: state.clients.concat(payload),
};
} else if (action.type === 'CLIENT_REMOVED') {
const {payload} = action;
return {
...state,
clients: state.clients.filter((client: Client) => client.id !== payload),
};
} else if (action.type === 'SERVER_ERROR') {
const {payload} = action;
return {...state, error: payload};
} else {
return state;
}
}