diff --git a/js/actionCreators/windows.js b/js/actionCreators/windows.ts similarity index 70% rename from js/actionCreators/windows.js rename to js/actionCreators/windows.ts index f96a46bf..830e43c0 100644 --- a/js/actionCreators/windows.js +++ b/js/actionCreators/windows.ts @@ -15,8 +15,9 @@ import { SET_WINDOW_VISIBILITY } from "../actionTypes"; -import { getPositionDiff } from "../resizeUtils"; +import { getPositionDiff, SizeDiff } from "../resizeUtils"; import { applyDiff } from "../snapUtils"; +import { Action, Dispatchable, WindowId, WindowPositions } from "../types"; // Dispatch an action and, if needed rearrange the windows to preserve // the existing edge relationship. @@ -24,7 +25,7 @@ import { applyDiff } from "../snapUtils"; // Works by checking the edges before the action is dispatched. Then, // after disatching, calculating what position change would be required // to restore those relationships. -function withWindowGraphIntegrity(action) { +function withWindowGraphIntegrity(action: Action): Dispatchable { return (dispatch, getState) => { const state = getState(); const graph = getWindowGraph(state); @@ -33,7 +34,7 @@ function withWindowGraphIntegrity(action) { dispatch(action); const newSizes = getWindowSizes(getState()); - const sizeDiff = {}; + const sizeDiff: SizeDiff = {}; for (const window of Object.keys(newSizes)) { const original = originalSizes[window]; const current = newSizes[window]; @@ -54,51 +55,56 @@ function withWindowGraphIntegrity(action) { }; } -export function toggleDoubleSizeMode() { +export function toggleDoubleSizeMode(): Dispatchable { return withWindowGraphIntegrity({ type: TOGGLE_DOUBLESIZE_MODE }); } -export function toggleEqualizerShadeMode() { +export function toggleEqualizerShadeMode(): Dispatchable { return withWindowGraphIntegrity({ type: TOGGLE_WINDOW_SHADE_MODE, windowId: "equalizer" }); } -export function toggleMainWindowShadeMode() { +export function toggleMainWindowShadeMode(): Dispatchable { return withWindowGraphIntegrity({ type: TOGGLE_WINDOW_SHADE_MODE, windowId: "main" }); } -export function togglePlaylistShadeMode() { +export function togglePlaylistShadeMode(): Dispatchable { return withWindowGraphIntegrity({ type: TOGGLE_WINDOW_SHADE_MODE, windowId: "playlist" }); } -export function closeWindow(windowId) { +export function closeWindow(windowId: WindowId): Dispatchable { return { type: CLOSE_WINDOW, windowId }; } -export function hideWindow(windowId) { +export function hideWindow(windowId: WindowId): Dispatchable { return { type: SET_WINDOW_VISIBILITY, windowId, hidden: true }; } -export function showWindow(windowId) { +export function showWindow(windowId: WindowId): Dispatchable { return { type: SET_WINDOW_VISIBILITY, windowId, hidden: false }; } -export function setWindowSize(windowId, size) { +export function setWindowSize( + windowId: WindowId, + size: [number, number] +): Dispatchable { return { type: WINDOW_SIZE_CHANGED, windowId, size }; } -export function toggleWindow(windowId) { +export function toggleWindow(windowId: WindowId): Dispatchable { return { type: TOGGLE_WINDOW, windowId }; } -export function updateWindowPositions(positions) { +export function updateWindowPositions( + positions: WindowPositions +): Dispatchable { return { type: UPDATE_WINDOW_POSITIONS, positions }; } diff --git a/js/resizeUtils.ts b/js/resizeUtils.ts index c6b72820..29fee02e 100644 --- a/js/resizeUtils.ts +++ b/js/resizeUtils.ts @@ -14,10 +14,8 @@ interface PositionDiff { }; } -interface SizeDiff { +export interface SizeDiff { [key: string]: { - x: number; - y: number; width: number; height: number; };