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). * (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'); export const LOCAL_RECORDING_ENGAGED = Symbol('LOCAL_RECORDING_ENGAGED');
@ -29,11 +30,12 @@ export const LOCAL_RECORDING_TOGGLE_DIALOG
= Symbol('LOCAL_RECORDING_TOGGLE_DIALOG'); = Symbol('LOCAL_RECORDING_TOGGLE_DIALOG');
/** /**
* Action to update {@code LocalRecordingInfoDialog} with stats * Action to update {@code LocalRecordingInfoDialog} with stats from all
* from all clients. * clients.
* *
* { * {
* type: LOCAL_RECORDING_STATS_UPDATE * type: LOCAL_RECORDING_STATS_UPDATE,
* stats: Object
* } * }
*/ */
export const LOCAL_RECORDING_STATS_UPDATE export const LOCAL_RECORDING_STATS_UPDATE

View File

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

View File

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

View File

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