Skip to content

Commit

Permalink
Use namespaced Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Oct 1, 2018
1 parent 1791bab commit 3049350
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions js/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import {
SerializedStateV1
} from "./types";
import { createSelector } from "reselect";
import {
denormalize,
getTimeStr,
clamp,
percentToIndex,
objectMap
} from "./utils";
import * as Utils from "./utils";
import {
BANDS,
TRACK_HEIGHT,
Expand All @@ -37,10 +31,10 @@ export const getSliders = (state: AppState) => state.equalizer.sliders;
export const getEqfData = createSelector(getSliders, sliders => {
const preset: { [key: string]: number | string } = {
name: "Entry1",
preamp: denormalize(sliders.preamp)
preamp: Utils.denormalize(sliders.preamp)
};
BANDS.forEach(band => {
preset[`hz${band}`] = denormalize(sliders[band]);
preset[`hz${band}`] = Utils.denormalize(sliders[band]);
});
const eqfData = {
presets: [preset],
Expand Down Expand Up @@ -93,7 +87,9 @@ export const getRunningTimeMessage = createSelector(
getTotalRunningTime,
getSelectedRunningTime,
(totalRunningTime, selectedRunningTime) =>
`${getTimeStr(selectedRunningTime)}/${getTimeStr(totalRunningTime)}`
`${Utils.getTimeStr(selectedRunningTime)}/${Utils.getTimeStr(
totalRunningTime
)}`
);

// TODO: use slectors to get memoization
Expand Down Expand Up @@ -141,7 +137,7 @@ export const nextTrack = (state: AppState, n = 1) => {
return null;
}

nextIndex = clamp(nextIndex, 0, trackCount - 1);
nextIndex = Utils.clamp(nextIndex, 0, trackCount - 1);
return trackOrder[nextIndex];
};

Expand Down Expand Up @@ -185,7 +181,7 @@ export const getScrollOffset = createSelector(
getNumberOfVisibleTracks,
(playlistScrollPosition, trackCount, numberOfVisibleTracks) => {
const overflow = Math.max(0, trackCount - numberOfVisibleTracks);
return percentToIndex(playlistScrollPosition / 100, overflow + 1);
return Utils.percentToIndex(playlistScrollPosition / 100, overflow + 1);
}
);

Expand Down Expand Up @@ -291,7 +287,7 @@ export const getMediaText = createSelector(
minimalMediaText == null
? null
: // TODO: Maybe the ` *** ` should actually be added by the marquee
`${minimalMediaText} (${getTimeStr(duration)}) *** `
`${minimalMediaText} (${Utils.getTimeStr(duration)}) *** `
);

export const getNumberOfTracks = (state: AppState) =>
Expand All @@ -312,13 +308,15 @@ export const getPlaylistURL = createSelector(
(numberOfTracks, playlistDuration, trackOrder, tracks, getDisplayName) =>
createPlaylistURL({
numberOfTracks,
averageTrackLength: getTimeStr(playlistDuration / numberOfTracks),
averageTrackLength: Utils.getTimeStr(playlistDuration / numberOfTracks),
// TODO: Handle hours
playlistLengthMinutes: Math.floor(playlistDuration / 60),
playlistLengthSeconds: Math.floor(playlistDuration % 60),
tracks: trackOrder.map(
(id, i) =>
`${i + 1}. ${getDisplayName(id)} (${getTimeStr(tracks[id].duration)})`
`${i + 1}. ${getDisplayName(id)} (${Utils.getTimeStr(
tracks[id].duration
)})`
)
})
);
Expand Down Expand Up @@ -371,7 +369,7 @@ export const getWindowSizes = createSelector(
getGenWindows,
getDoubled,
(windows, doubled) => {
return objectMap(windows, w => getWPixelSize(w, doubled));
return Utils.objectMap(windows, w => getWPixelSize(w, doubled));
}
);

Expand Down

0 comments on commit 3049350

Please sign in to comment.