reducer should be a pure function

This commit is contained in:
Radium Zheng 2018-07-11 00:26:16 +10:00
parent 2dfb107c57
commit 0f3b67e53e
5 changed files with 24 additions and 17 deletions

View File

@ -3,7 +3,8 @@
* (as in: {@code RecordingAdapter} is actively collecting audio data).
*
* {
* type: LOCAL_RECORDING_ENGAGED
* type: LOCAL_RECORDING_ENGAGED,
* recordingEngagedAt: Date
* }
*/
export const LOCAL_RECORDING_ENGAGED = Symbol('LOCAL_RECORDING_ENGAGED');
@ -29,11 +30,12 @@ export const LOCAL_RECORDING_TOGGLE_DIALOG
= Symbol('LOCAL_RECORDING_TOGGLE_DIALOG');
/**
* Action to update {@code LocalRecordingInfoDialog} with stats
* from all clients.
* Action to update {@code LocalRecordingInfoDialog} with stats from all
* clients.
*
* {
* type: LOCAL_RECORDING_STATS_UPDATE
* type: LOCAL_RECORDING_STATS_UPDATE,
* stats: Object
* }
*/
export const LOCAL_RECORDING_STATS_UPDATE

View File

@ -14,15 +14,18 @@ import {
// recording in the UI.
/**
* Signals that local recording has started.
* Signals that local recording has been engaged.
*
* @param {Date} startTime - Time when the recording is engaged.
* @returns {{
* type: LOCAL_RECORDING_ENGAGED
* type: LOCAL_RECORDING_ENGAGED,
* recordingEngagedAt: Date
* }}
*/
export function localRecordingEngaged() {
export function localRecordingEngaged(startTime: Date) {
return {
type: LOCAL_RECORDING_ENGAGED
type: LOCAL_RECORDING_ENGAGED,
recordingEngagedAt: startTime
};
}

View File

@ -44,7 +44,7 @@ type Props = {
* The start time of the current local recording session.
* Used to calculate the duration of recording.
*/
recordingStartedAt: Date,
recordingEngagedAt: Date,
/**
* Stats of all the participant.
@ -103,11 +103,11 @@ class LocalRecordingInfoDialog extends Component<Props, State> {
this._timer = setInterval(
() => {
this.setState((_prevState, props) => {
const nowTime = new Date(Date.now());
const nowTime = new Date();
return {
durationString: this._getDuration(nowTime,
props.recordingStartedAt)
props.recordingEngagedAt)
};
});
try {
@ -312,7 +312,7 @@ class LocalRecordingInfoDialog extends Component<Props, State> {
* encodingFormat: string,
* isModerator: boolean,
* isOn: boolean,
* recordingStartedAt: Date,
* recordingEngagedAt: Date,
* stats: Object
* }}
*/
@ -320,7 +320,7 @@ function _mapStateToProps(state) {
const {
encodingFormat,
isEngaged: isOn,
recordingStartedAt,
recordingEngagedAt,
stats
} = state['features/local-recording'];
const isModerator
@ -330,7 +330,7 @@ function _mapStateToProps(state) {
encodingFormat,
isModerator,
isOn,
recordingStartedAt,
recordingEngagedAt,
stats
};
}

View File

@ -24,7 +24,9 @@ MiddlewareRegistry.register(({ getState, dispatch }) => next => action => {
// react to state changes in recordingController.
recordingController.onStateChanged = function(isEngaged) {
if (isEngaged) {
dispatch(localRecordingEngaged());
const nowTime = new Date();
dispatch(localRecordingEngaged(nowTime));
} else {
dispatch(localRecordingUnengaged());
}

View File

@ -15,7 +15,7 @@ ReducerRegistry.register('features/local-recording', (state = {}, action) => {
return {
...state,
isEngaged: true,
recordingStartedAt: new Date(Date.now()),
recordingEngagedAt: action.recordingEngagedAt,
encodingFormat: recordingController._format
};
}
@ -23,7 +23,7 @@ ReducerRegistry.register('features/local-recording', (state = {}, action) => {
return {
...state,
isEngaged: false,
recordingStartedAt: null
recordingEngagedAt: null
};
case LOCAL_RECORDING_TOGGLE_DIALOG:
return {