Skip to content

Commit c762cd8

Browse files
olzzonolzzon
olzzon
authored and
olzzon
committed
chore: refactor Redux fader store - all actions are now based on Action Creators for better typechecking
1 parent f7dc132 commit c762cd8

7 files changed

+168
-150
lines changed

server/MainThreadHandler.ts

+24-34
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ import {
6363
SOCKET_TOGGLE_ALL_MANUAL,
6464
} from './constants/SOCKET_IO_DISPATCHERS'
6565
import {
66-
NEXT_MIX,
67-
CLEAR_PST,
68-
IGNORE_AUTOMATION,
69-
SHOW_IN_MINI_MONITOR,
70-
SET_INPUT_SELECTOR,
71-
TOGGLE_AMIX,
72-
TOGGLE_ALL_MANUAL,
7366
storeFaderLevel,
7467
storeInputGain,
7568
storeFaderThreshold,
@@ -85,6 +78,13 @@ import {
8578
storeTogglePst,
8679
storeTogglePfl,
8780
storeToggleMute,
81+
storeToggleIgnoreAutomation,
82+
storeShowInMiniMonitor,
83+
storeNextMix,
84+
storeClearPst,
85+
storeToggleAMix,
86+
storeAllManual,
87+
storeInputSelector,
8888
} from './reducers/faderActions'
8989
import {
9090
storeSetAssignedFader,
@@ -238,11 +238,12 @@ export class MainThreadHandlers {
238238
this.updateFullClientStore()
239239
})
240240
.on(SOCKET_SHOW_IN_MINI_MONITOR, (payload: any) => {
241-
store.dispatch({
242-
type: SHOW_IN_MINI_MONITOR,
243-
faderIndex: payload.faderIndex,
244-
showInMiniMonitor: payload.showInMiniMonitor,
245-
})
241+
store.dispatch(
242+
storeShowInMiniMonitor(
243+
payload.faderIndex,
244+
payload.showInMiniMonitor
245+
)
246+
)
246247
this.updateFullClientStore()
247248
})
248249
.on(SOCKET_SET_INPUT_OPTION, (payload: any) => {
@@ -319,16 +320,12 @@ export class MainThreadHandlers {
319320
this.updatePartialStore(payload.channel)
320321
})
321322
.on(SOCKET_NEXT_MIX, () => {
322-
store.dispatch({
323-
type: NEXT_MIX,
324-
})
323+
store.dispatch(storeNextMix())
325324
mixerGenericConnection.updateOutLevels()
326325
this.updateFullClientStore()
327326
})
328327
.on(SOCKET_CLEAR_PST, () => {
329-
store.dispatch({
330-
type: CLEAR_PST,
331-
})
328+
store.dispatch(storeClearPst())
332329
mixerGenericConnection.updateOutLevels()
333330
this.updateFullClientStore()
334331
})
@@ -360,18 +357,12 @@ export class MainThreadHandlers {
360357
this.updatePartialStore(faderIndex)
361358
})
362359
.on(SOCKET_TOGGLE_AMIX, (faderIndex: any) => {
363-
store.dispatch({
364-
type: TOGGLE_AMIX,
365-
channel: faderIndex,
366-
})
360+
store.dispatch(storeToggleAMix(faderIndex))
367361
mixerGenericConnection.updateAMixState(faderIndex)
368362
this.updatePartialStore(faderIndex)
369363
})
370364
.on(SOCKET_TOGGLE_IGNORE, (faderIndex: any) => {
371-
store.dispatch({
372-
type: IGNORE_AUTOMATION,
373-
channel: faderIndex,
374-
})
365+
store.dispatch(storeToggleIgnoreAutomation(faderIndex))
375366
this.updatePartialStore(faderIndex)
376367
})
377368
.on(SOCKET_SET_FADERLEVEL, (payload: any) => {
@@ -415,19 +406,18 @@ export class MainThreadHandlers {
415406
String(payload.selected)
416407
)
417408
console.log(payload)
418-
store.dispatch({
419-
type: SET_INPUT_SELECTOR,
420-
channel: payload.faderIndex,
421-
selected: parseFloat(payload.selected),
422-
})
409+
store.dispatch(
410+
storeInputSelector(
411+
payload.faderIndex,
412+
parseFloat(payload.selected)
413+
)
414+
)
423415
mixerGenericConnection.updateInputSelector(payload.faderIndex)
424416
this.updatePartialStore(payload.faderIndex)
425417
})
426418
.on(SOCKET_TOGGLE_ALL_MANUAL, () => {
427419
logger.verbose('Toggle manual mode for all')
428-
store.dispatch({
429-
type: TOGGLE_ALL_MANUAL,
430-
})
420+
store.dispatch(storeAllManual())
431421
this.updateFullClientStore()
432422
})
433423
}

server/__tests__/faderReducer.spec.ts

-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
SET_MUTE,
1010
SET_CHANNEL_LABEL,
1111
SET_PST_VO,
12-
TOGGLE_SNAP,
1312
TOGGLE_MUTE,
1413
TOGGLE_PFL,
1514
TOGGLE_PGM,
@@ -148,18 +147,6 @@ describe('Test redux faderReducers actions', () => {
148147
* TEST ALL TOGGLE ACTIONS
149148
*/
150149

151-
it('should return the new SNAP state on faders', () => {
152-
let parsedInitialStore = JSON.parse(parsedSimpleStoreJSON)
153-
parsedInitialStore.faders[0].fader[0].snapOn[0] = true
154-
expect(
155-
indexReducer(JSON.parse(parsedSimpleStoreJSON), {
156-
type: TOGGLE_SNAP,
157-
channel: 0,
158-
snapIndex: 0,
159-
})
160-
).toEqual(parsedInitialStore)
161-
})
162-
163150
it('should return the new TOGGLE pgmOn state on faders', () => {
164151
let parsedInitialStore = JSON.parse(parsedSimpleStoreJSON)
165152
parsedInitialStore.faders[0].fader[0].pgmOn = true

server/reducers/faderActions.ts

+85-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ export const TOGGLE_PFL = 'TOGGLE_PFL'
2727
export const SET_PFL = 'SET_PFL'
2828
export const TOGGLE_MUTE = 'TOGGLE_MUTE'
2929
export const SET_MUTE = 'SET_MUTE'
30-
3130
export const SHOW_CHANNEL = 'SHOW_CHANNEL'
3231
export const SHOW_IN_MINI_MONITOR = 'SHOW_IN_MINI_MONITOR'
3332
export const IGNORE_AUTOMATION = 'IGNORE_AUTOMATION'
34-
export const TOGGLE_SNAP = 'TOGGLE_SNAP'
3533
export const X_MIX = 'X_MIX'
3634
export const NEXT_MIX = 'NEXT_MIX'
3735
export const FADE_TO_BLACK = 'FADE_TO_BLACK'
36+
3837
export const CLEAR_PST = 'CLEAR_PST'
3938
export const SNAP_RECALL = 'SNAP_RECALL'
4039
export const SET_CHANNEL_DISABLED = 'SET_CHANNEL_DISABLED'
@@ -264,3 +263,87 @@ export const storeShowChannel = (channel: number, showChannel: boolean) => {
264263
showChannel: showChannel,
265264
}
266265
}
266+
267+
export const storeShowInMiniMonitor = (
268+
faderIndex: number,
269+
showInMiniMonitor: boolean
270+
) => {
271+
return {
272+
type: SHOW_IN_MINI_MONITOR,
273+
faderIndex: faderIndex,
274+
showInMiniMonitor: showInMiniMonitor,
275+
}
276+
}
277+
278+
export const storeToggleIgnoreAutomation = (channel: number) => {
279+
return {
280+
type: IGNORE_AUTOMATION,
281+
channel: channel,
282+
}
283+
}
284+
285+
export const storeXmix = () => {
286+
return {
287+
type: X_MIX,
288+
}
289+
}
290+
291+
export const storeNextMix = () => {
292+
return {
293+
type: NEXT_MIX,
294+
}
295+
}
296+
297+
export const storeFadeToBlack = () => {
298+
return {
299+
type: FADE_TO_BLACK,
300+
}
301+
}
302+
303+
export const storeClearPst = () => {
304+
return {
305+
type: CLEAR_PST,
306+
}
307+
}
308+
309+
export const storeChannelDisabled = (channel: number, disabled: boolean) => {
310+
return {
311+
type: SET_CHANNEL_DISABLED,
312+
channel: channel,
313+
disabled: disabled,
314+
}
315+
}
316+
317+
export const storeToggleAMix = (channel: number) => {
318+
return {
319+
type: TOGGLE_AMIX,
320+
channel: channel,
321+
}
322+
}
323+
324+
export const storeSetAMix = (channel: number, state: boolean) => {
325+
return {
326+
type: SET_AMIX,
327+
channel: channel,
328+
state: state,
329+
}
330+
}
331+
332+
export const storeCapability = (
333+
channel: number,
334+
capability: string,
335+
enabled: boolean
336+
) => {
337+
return {
338+
type: SET_CAPABILITY,
339+
channel: channel,
340+
capability: capability,
341+
enabled: enabled,
342+
}
343+
}
344+
345+
export const storeAllManual = () => {
346+
return {
347+
type: TOGGLE_ALL_MANUAL,
348+
}
349+
}

server/reducers/fadersReducer.ts

-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
SET_PGM,
1313
SET_PST,
1414
SET_PST_VO,
15-
TOGGLE_SNAP,
1615
SET_VO,
1716
SET_VU_LEVEL,
1817
SET_VU_REDUCTION_LEVEL,
@@ -301,11 +300,6 @@ export const faders = (
301300
nextState[0].fader[action.channel].ignoreAutomation = !nextState[0]
302301
.fader[action.channel].ignoreAutomation
303302
return nextState
304-
case TOGGLE_SNAP: //channel //snapIndex
305-
nextState[0].fader[action.channel].snapOn[
306-
action.snapIndex
307-
] = !nextState[0].fader[action.channel].snapOn[action.snapIndex]
308-
return nextState
309303
case X_MIX: //none
310304
nextState[0].fader.forEach((item, index) => {
311305
let nextPgmOn = state[0].fader[index].pstOn

server/utils/AutomationConnection.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import {
1010
} from '../constants/AutomationPresets'
1111
import { IFader } from '../reducers/fadersReducer'
1212
import {
13-
X_MIX,
14-
FADE_TO_BLACK,
15-
CLEAR_PST,
1613
SNAP_RECALL,
1714
storeFaderLevel,
1815
storeFaderLabel,
@@ -22,6 +19,9 @@ import {
2219
storeSetMute,
2320
storeSetPst,
2421
storeShowChannel,
22+
storeXmix,
23+
storeFadeToBlack,
24+
storeClearPst,
2525
} from '../reducers/faderActions'
2626
import { logger } from './logger'
2727

@@ -182,9 +182,7 @@ export class AutomationConnection {
182182
this.automationProtocol.fromAutomation.X_MIX
183183
)
184184
) {
185-
store.dispatch({
186-
type: X_MIX,
187-
})
185+
store.dispatch(storeXmix())
188186
mixerGenericConnection.updateOutLevels()
189187
global.mainThreadHandler.updateFullClientStore()
190188
} else if (
@@ -205,9 +203,7 @@ export class AutomationConnection {
205203
this.automationProtocol.fromAutomation.FADE_TO_BLACK
206204
)
207205
) {
208-
store.dispatch({
209-
type: FADE_TO_BLACK,
210-
})
206+
store.dispatch(storeFadeToBlack())
211207
mixerGenericConnection.updateFadeToBlack()
212208
global.mainThreadHandler.updateFullClientStore()
213209
} else if (
@@ -216,9 +212,7 @@ export class AutomationConnection {
216212
this.automationProtocol.fromAutomation.CLEAR_PST
217213
)
218214
) {
219-
store.dispatch({
220-
type: CLEAR_PST,
221-
})
215+
store.dispatch(storeClearPst())
222216
mixerGenericConnection.updateOutLevels()
223217
global.mainThreadHandler.updateFullClientStore()
224218
// Get state from Producers Audio Mixer:

0 commit comments

Comments
 (0)