Skip to content

Commit e1f4a6e

Browse files
committed
Pull marquee stepping out of Redux
1 parent 17a835c commit e1f4a6e

File tree

9 files changed

+20
-37
lines changed

9 files changed

+20
-37
lines changed

packages/webamp/demo/js/Webamp.ts

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export {
2020
} from "../../js/types";
2121
export { WINDOWS } from "../../js/constants";
2222
export {
23-
STEP_MARQUEE,
2423
UPDATE_TIME_ELAPSED,
2524
UPDATE_WINDOW_POSITIONS,
2625
SET_VOLUME,

packages/webamp/demo/js/webampConfig.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Options,
1212
PrivateOptions,
1313
WINDOWS,
14-
STEP_MARQUEE,
1514
UPDATE_TIME_ELAPSED,
1615
UPDATE_WINDOW_POSITIONS,
1716
SET_VOLUME,
@@ -29,7 +28,6 @@ import { initialTracks, initialState } from "./config";
2928
import screenshotInitialState from "./screenshotInitialState";
3029

3130
const NOISY_ACTION_TYPES = new Set([
32-
STEP_MARQUEE,
3331
UPDATE_TIME_ELAPSED,
3432
UPDATE_WINDOW_POSITIONS,
3533
SET_VOLUME,

packages/webamp/js/actionCreators/index.ts

-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
SET_MILKDROP_DESKTOP,
1313
SET_MILKDROP_FULLSCREEN,
1414
TOGGLE_PRESET_OVERLAY,
15-
STEP_MARQUEE,
1615
SET_BAND_FOCUS,
1716
} from "../actionTypes";
1817
import { WINDOWS } from "../constants";
@@ -215,7 +214,3 @@ export function togglePresetOverlay(): Thunk {
215214
dispatch({ type: TOGGLE_PRESET_OVERLAY });
216215
};
217216
}
218-
219-
export function stepMarquee(): Action {
220-
return { type: STEP_MARQUEE };
221-
}

packages/webamp/js/actionTypes.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const SET_SCRUB_POSITION = "SET_SCRUB_POSITION";
1717
export const SET_SKIN_DATA = "SET_SKIN_DATA";
1818
export const SET_VOLUME = "SET_VOLUME";
1919
export const START_WORKING = "START_WORKING";
20-
export const STEP_MARQUEE = "STEP_MARQUEE";
2120
export const STOP = "STOP";
2221
export const STOP_WORKING = "STOP_WORKING";
2322
export const TOGGLE_DOUBLESIZE_MODE = "TOGGLE_DOUBLESIZE_MODE";

packages/webamp/js/components/MainWindow/Marquee.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// Knows how to display various modes like tracking, volume, balance, etc.
33
import * as React from "react";
44
import CharacterString from "../CharacterString";
5-
import * as Actions from "../../actionCreators";
65
import * as Selectors from "../../selectors";
7-
import { useTypedSelector, useActionCreator } from "../../hooks";
6+
import { useTypedSelector } from "../../hooks";
87

98
const SEPARATOR = " *** ";
109

@@ -43,20 +42,24 @@ export const loopText = (text: string): string =>
4342
: text.padEnd(MARQUEE_MAX_LENGTH, " ");
4443

4544
interface UseStepperArgs {
46-
step: () => void;
4745
dragging: boolean;
46+
disableMarquee: boolean;
4847
}
4948

5049
// Call `step` every second, except when dragging. Resume stepping 1 second after dragging ceases.
51-
function useStepper({ step, dragging }: UseStepperArgs): void {
50+
function useStepper({ dragging, disableMarquee }: UseStepperArgs): number {
51+
const [currentStep, setStep] = React.useState(0);
5252
const [stepping, setStepping] = React.useState(true);
5353
React.useEffect(() => {
54-
if (stepping === false) {
54+
if (stepping === false || disableMarquee === true) {
5555
return;
5656
}
57-
const stepHandle = setInterval(step, 220);
57+
const stepHandle = setInterval(
58+
() => setStep((current) => current + 1),
59+
220
60+
);
5861
return () => clearInterval(stepHandle);
59-
}, [step, stepping]);
62+
}, [stepping, disableMarquee]);
6063

6164
React.useEffect(() => {
6265
if (dragging) {
@@ -70,6 +73,7 @@ function useStepper({ step, dragging }: UseStepperArgs): void {
7073
window.clearTimeout(steppingTimeout);
7174
};
7275
}, [dragging]);
76+
return currentStep;
7377
}
7478

7579
// When user calls `handleMouseDown`, and moves the mouse, `dragOffset` will update as they drag.
@@ -118,14 +122,12 @@ function useDragX() {
118122
const Marquee = React.memo(() => {
119123
const text = useTypedSelector(Selectors.getMarqueeText);
120124
const doubled = useTypedSelector(Selectors.getDoubled);
121-
const marqueeStep = useTypedSelector(Selectors.getMarqueeStep);
122-
const stepMarquee = useActionCreator(Actions.stepMarquee);
123125
const { handleMouseDown, dragOffset, dragging } = useDragX();
126+
const disableMarquee = useTypedSelector(Selectors.getDisableMarquee);
127+
const marqueeStep = useStepper({ dragging, disableMarquee });
124128
const offset = stepOffset(text, marqueeStep, dragOffset);
125129
const offsetPixels = pixelUnits(-offset);
126130

127-
useStepper({ step: stepMarquee, dragging });
128-
129131
return (
130132
<div
131133
id="marquee"

packages/webamp/js/reducers/display.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
OPEN_WINAMP,
1717
SET_SKIN_DATA,
1818
START_WORKING,
19-
STEP_MARQUEE,
2019
STOP_WORKING,
2120
TOGGLE_DOUBLESIZE_MODE,
2221
TOGGLE_LLAMA_MODE,
@@ -38,7 +37,6 @@ export interface DisplayState {
3837
doubled: boolean;
3938
llama: boolean;
4039
disableMarquee: boolean;
41-
marqueeStep: number;
4240
skinImages: SkinImages;
4341
skinCursors: Cursors | null;
4442
skinRegion: SkinRegion;
@@ -131,10 +129,6 @@ const display = (
131129
return { ...state, doubled: !state.doubled };
132130
case TOGGLE_LLAMA_MODE:
133131
return { ...state, llama: !state.llama };
134-
case STEP_MARQUEE:
135-
return state.disableMarquee
136-
? state
137-
: { ...state, marqueeStep: state.marqueeStep + 1 };
138132
case DISABLE_MARQUEE:
139133
return { ...state, disableMarquee: true };
140134
case STOP_WORKING:
@@ -194,7 +188,6 @@ export const getSerializedState = (
194188
visualizerStyle,
195189
doubled,
196190
llama,
197-
marqueeStep,
198191
skinImages,
199192
skinCursors,
200193
skinRegion,
@@ -217,7 +210,7 @@ export const getSerializedState = (
217210
visualizerStyle,
218211
doubled,
219212
llama,
220-
marqueeStep,
213+
marqueeStep: 0, // This is not used any more.
221214
skinImages,
222215
skinCursors: newCursors,
223216
skinRegion,

packages/webamp/js/selectors.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ export const getMarqueeText = (state: AppState): string => {
636636
return defaultText;
637637
};
638638

639+
export function getDisableMarquee(state: AppState): boolean {
640+
return state.display.disableMarquee;
641+
}
642+
639643
export const getKbps = createSelector(
640644
getCurrentTrack,
641645
(track: PlaylistTrack | null): string | null => {
@@ -757,10 +761,6 @@ export function getDummyVizData(state: AppState): DummyVizData | null {
757761
return state.display.dummyVizData;
758762
}
759763

760-
export function getMarqueeStep(state: AppState): number {
761-
return state.display.marqueeStep;
762-
}
763-
764764
export function getNetworkConnected(state: AppState): boolean {
765765
return state.network.connected;
766766
}

packages/webamp/js/store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { composeWithDevTools } from "redux-devtools-extension";
44
import reducer from "./reducers";
55
import mediaMiddleware from "./mediaMiddleware";
66
import { merge } from "./utils";
7-
import { UPDATE_TIME_ELAPSED, STEP_MARQUEE } from "./actionTypes";
7+
import { UPDATE_TIME_ELAPSED } from "./actionTypes";
88
import Media from "./media";
99
import Emitter from "./emitter";
1010
import { Extras, Dispatch, Action, AppState, Middleware } from "./types";
1111

1212
// TODO: Move to demo
1313
const compose = composeWithDevTools({
14-
actionsBlacklist: [UPDATE_TIME_ELAPSED, STEP_MARQUEE],
14+
actionsBlacklist: [UPDATE_TIME_ELAPSED],
1515
});
1616

1717
export default function (

packages/webamp/js/types.ts

-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ export type Action =
319319
| {
320320
type: "TOGGLE_LLAMA_MODE";
321321
}
322-
| {
323-
type: "STEP_MARQUEE";
324-
}
325322
| {
326323
type: "DISABLE_MARQUEE";
327324
}

0 commit comments

Comments
 (0)