fbshipit-source-id: c71048dfea2a03cf83650b55aa9d1e463251920c
This commit is contained in:
@@ -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
54
src/reducers/server.js
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user