add/update action creators types

This commit is contained in:
Labhansh Agrawal 2020-01-02 23:57:27 +05:30 committed by Benjamin Staneck
parent c0b72f9939
commit 9485b3297e
8 changed files with 71 additions and 70 deletions

View file

@ -1,13 +1,14 @@
import {CONFIG_LOAD, CONFIG_RELOAD} from '../constants/config'; import {CONFIG_LOAD, CONFIG_RELOAD} from '../constants/config';
import {HyperActions} from '../hyper';
export function loadConfig(config) { export function loadConfig(config: any): HyperActions {
return { return {
type: CONFIG_LOAD, type: CONFIG_LOAD,
config config
}; };
} }
export function reloadConfig(config) { export function reloadConfig(config: any): HyperActions {
const now = Date.now(); const now = Date.now();
return { return {
type: CONFIG_RELOAD, type: CONFIG_RELOAD,

View file

@ -8,9 +8,10 @@ import {
} from '../constants/ui'; } from '../constants/ui';
import rpc from '../rpc'; import rpc from '../rpc';
import {userExitTermGroup, setActiveGroup} from './term-groups'; import {userExitTermGroup, setActiveGroup} from './term-groups';
import {HyperDispatch} from '../hyper';
export function closeTab(uid) { export function closeTab(uid: string) {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: CLOSE_TAB, type: CLOSE_TAB,
uid, uid,
@ -21,8 +22,8 @@ export function closeTab(uid) {
}; };
} }
export function changeTab(uid) { export function changeTab(uid: string) {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: CHANGE_TAB, type: CHANGE_TAB,
uid, uid,
@ -34,29 +35,29 @@ export function changeTab(uid) {
} }
export function maximize() { export function maximize() {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_WINDOW_MAXIMIZE, type: UI_WINDOW_MAXIMIZE,
effect() { effect() {
rpc.emit('maximize'); rpc.emit('maximize', null);
} }
}); });
}; };
} }
export function unmaximize() { export function unmaximize() {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_WINDOW_UNMAXIMIZE, type: UI_WINDOW_UNMAXIMIZE,
effect() { effect() {
rpc.emit('unmaximize'); rpc.emit('unmaximize', null);
} }
}); });
}; };
} }
export function openHamburgerMenu(coordinates) { export function openHamburgerMenu(coordinates: {x: number; y: number}) {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_OPEN_HAMBURGER_MENU, type: UI_OPEN_HAMBURGER_MENU,
effect() { effect() {
@ -67,22 +68,22 @@ export function openHamburgerMenu(coordinates) {
} }
export function minimize() { export function minimize() {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_WINDOW_MINIMIZE, type: UI_WINDOW_MINIMIZE,
effect() { effect() {
rpc.emit('minimize'); rpc.emit('minimize', null);
} }
}); });
}; };
} }
export function close() { export function close() {
return dispatch => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_WINDOW_CLOSE, type: UI_WINDOW_CLOSE,
effect() { effect() {
rpc.emit('close'); rpc.emit('close', null);
} }
}); });
}; };

View file

@ -1,9 +1,9 @@
import rpc from '../rpc'; import rpc from '../rpc';
import {INIT} from '../constants'; import {INIT} from '../constants';
import {Dispatch} from 'redux'; import {HyperDispatch} from '../hyper';
export default function init() { export default function init() {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: INIT, type: INIT,
effect: () => { effect: () => {

View file

@ -1,13 +1,14 @@
import {NOTIFICATION_MESSAGE, NOTIFICATION_DISMISS} from '../constants/notifications'; import {NOTIFICATION_MESSAGE, NOTIFICATION_DISMISS} from '../constants/notifications';
import {HyperActions} from '../hyper';
export function dismissNotification(id: string) { export function dismissNotification(id: string): HyperActions {
return { return {
type: NOTIFICATION_DISMISS, type: NOTIFICATION_DISMISS,
id id
}; };
} }
export function addNotificationMessage(text: string, url: string | null = null, dismissable = true) { export function addNotificationMessage(text: string, url: string | null = null, dismissable = true): HyperActions {
return { return {
type: NOTIFICATION_MESSAGE, type: NOTIFICATION_MESSAGE,
text, text,

View file

@ -16,11 +16,10 @@ import {
SESSION_SEARCH, SESSION_SEARCH,
SESSION_SEARCH_CLOSE SESSION_SEARCH_CLOSE
} from '../constants/sessions'; } from '../constants/sessions';
import {HyperState, session} from '../hyper'; import {HyperState, session, HyperDispatch, HyperActions} from '../hyper';
import {Dispatch} from 'redux';
export function addSession({uid, shell, pid, cols, rows, splitDirection, activeUid}: session) { export function addSession({uid, shell, pid, cols, rows, splitDirection, activeUid}: session) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const {sessions} = getState(); const {sessions} = getState();
const now = Date.now(); const now = Date.now();
dispatch({ dispatch({
@ -38,7 +37,7 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection, activeU
} }
export function requestSession() { export function requestSession() {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: SESSION_REQUEST, type: SESSION_REQUEST,
effect: () => { effect: () => {
@ -52,7 +51,7 @@ export function requestSession() {
} }
export function addSessionData(uid: string, data: any) { export function addSessionData(uid: string, data: any) {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: SESSION_ADD_DATA, type: SESSION_ADD_DATA,
data, data,
@ -69,8 +68,8 @@ export function addSessionData(uid: string, data: any) {
}; };
} }
function createExitAction(type: string) { function createExitAction(type: typeof SESSION_USER_EXIT | typeof SESSION_PTY_EXIT) {
return (uid: string) => (dispatch: Dispatch<any>, getState: () => HyperState) => { return (uid: string) => (dispatch: HyperDispatch, getState: () => HyperState) => {
return dispatch({ return dispatch({
type, type,
uid, uid,
@ -84,7 +83,7 @@ function createExitAction(type: string) {
window.close(); window.close();
} }
} }
}); } as HyperActions);
}; };
} }
@ -94,7 +93,7 @@ export const userExitSession = createExitAction(SESSION_USER_EXIT);
export const ptyExitSession = createExitAction(SESSION_PTY_EXIT); export const ptyExitSession = createExitAction(SESSION_PTY_EXIT);
export function setActiveSession(uid: string) { export function setActiveSession(uid: string) {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: SESSION_SET_ACTIVE, type: SESSION_SET_ACTIVE,
uid uid
@ -102,13 +101,13 @@ export function setActiveSession(uid: string) {
}; };
} }
export function clearActiveSession() { export function clearActiveSession(): HyperActions {
return { return {
type: SESSION_CLEAR_ACTIVE type: SESSION_CLEAR_ACTIVE
}; };
} }
export function setSessionXtermTitle(uid: string, title: string) { export function setSessionXtermTitle(uid: string, title: string): HyperActions {
return { return {
type: SESSION_SET_XTERM_TITLE, type: SESSION_SET_XTERM_TITLE,
uid, uid,
@ -117,7 +116,7 @@ export function setSessionXtermTitle(uid: string, title: string) {
} }
export function resizeSession(uid: string, cols: number, rows: number) { export function resizeSession(uid: string, cols: number, rows: number) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const {termGroups} = getState(); const {termGroups} = getState();
const group = findBySession(termGroups, uid)!; const group = findBySession(termGroups, uid)!;
const isStandaloneTerm = !group.parentUid && !group.children.length; const isStandaloneTerm = !group.parentUid && !group.children.length;
@ -137,8 +136,8 @@ export function resizeSession(uid: string, cols: number, rows: number) {
} }
export function onSearch(uid?: string) { export function onSearch(uid?: string) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const targetUid = uid || getState().sessions.activeUid; const targetUid = uid || getState().sessions.activeUid!;
dispatch({ dispatch({
type: SESSION_SEARCH, type: SESSION_SEARCH,
uid: targetUid uid: targetUid
@ -147,8 +146,8 @@ export function onSearch(uid?: string) {
} }
export function closeSearch(uid?: string) { export function closeSearch(uid?: string) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const targetUid = uid || getState().sessions.activeUid; const targetUid = uid || getState().sessions.activeUid!;
dispatch({ dispatch({
type: SESSION_SEARCH_CLOSE, type: SESSION_SEARCH_CLOSE,
uid: targetUid uid: targetUid
@ -157,7 +156,7 @@ export function closeSearch(uid?: string) {
} }
export function sendSessionData(uid: string | null, data: any, escaped?: any) { export function sendSessionData(uid: string | null, data: any, escaped?: any) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: SESSION_USER_DATA, type: SESSION_USER_DATA,
data, data,

View file

@ -10,12 +10,11 @@ import {SESSION_REQUEST} from '../constants/sessions';
import findBySession from '../utils/term-groups'; import findBySession from '../utils/term-groups';
import {getRootGroups} from '../selectors'; import {getRootGroups} from '../selectors';
import {setActiveSession, ptyExitSession, userExitSession} from './sessions'; import {setActiveSession, ptyExitSession, userExitSession} from './sessions';
import {Dispatch} from 'redux'; import {ITermState, ITermGroup, HyperState, HyperDispatch} from '../hyper';
import {ITermState, ITermGroup, HyperState} from '../hyper';
import {Immutable} from 'seamless-immutable'; import {Immutable} from 'seamless-immutable';
function requestSplit(direction: string) { function requestSplit(direction: string) {
return (activeUid: string) => (dispatch: Dispatch<any>, getState: () => HyperState): void => { return (activeUid: string) => (dispatch: HyperDispatch, getState: () => HyperState): void => {
dispatch({ dispatch({
type: SESSION_REQUEST, type: SESSION_REQUEST,
effect: () => { effect: () => {
@ -42,7 +41,7 @@ export function resizeTermGroup(uid: string, sizes: number[]) {
} }
export function requestTermGroup(activeUid: string) { export function requestTermGroup(activeUid: string) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: TERM_GROUP_REQUEST, type: TERM_GROUP_REQUEST,
effect: () => { effect: () => {
@ -59,7 +58,7 @@ export function requestTermGroup(activeUid: string) {
} }
export function setActiveGroup(uid: string) { export function setActiveGroup(uid: string) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const {termGroups} = getState(); const {termGroups} = getState();
dispatch(setActiveSession(termGroups.activeSessions[uid])); dispatch(setActiveSession(termGroups.activeSessions[uid]));
}; };
@ -106,7 +105,7 @@ const findNextSessionUid = (state: Immutable<ITermState>, group: Immutable<ITerm
}; };
export function ptyExitTermGroup(sessionUid: string) { export function ptyExitTermGroup(sessionUid: string) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const {termGroups} = getState(); const {termGroups} = getState();
const group = findBySession(termGroups, sessionUid); const group = findBySession(termGroups, sessionUid);
// This might have already been closed: // This might have already been closed:
@ -131,7 +130,7 @@ export function ptyExitTermGroup(sessionUid: string) {
} }
export function userExitTermGroup(uid: string) { export function userExitTermGroup(uid: string) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
const {termGroups} = getState(); const {termGroups} = getState();
dispatch({ dispatch({
type: TERM_GROUP_EXIT, type: TERM_GROUP_EXIT,
@ -163,7 +162,7 @@ export function userExitTermGroup(uid: string) {
} }
export function exitActiveTermGroup() { export function exitActiveTermGroup() {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: TERM_GROUP_EXIT_ACTIVE, type: TERM_GROUP_EXIT_ACTIVE,
effect() { effect() {

View file

@ -4,7 +4,7 @@ import {getRootGroups} from '../selectors';
import findBySession from '../utils/term-groups'; import findBySession from '../utils/term-groups';
import notify from '../utils/notify'; import notify from '../utils/notify';
import rpc from '../rpc'; import rpc from '../rpc';
import {requestSession, sendSessionData, setActiveSession} from '../actions/sessions'; import {requestSession, sendSessionData, setActiveSession} from './sessions';
import { import {
UI_FONT_SIZE_SET, UI_FONT_SIZE_SET,
UI_FONT_SIZE_INCR, UI_FONT_SIZE_INCR,
@ -28,14 +28,13 @@ import {
import {setActiveGroup} from './term-groups'; import {setActiveGroup} from './term-groups';
import parseUrl from 'parse-url'; import parseUrl from 'parse-url';
import {Dispatch} from 'redux'; import {HyperState, HyperDispatch, HyperActions} from '../hyper';
import {HyperState} from '../hyper';
import {Stats} from 'fs'; import {Stats} from 'fs';
const {stat} = window.require('fs'); const {stat} = window.require('fs');
export function openContextMenu(uid: string, selection: any) { export function openContextMenu(uid: string, selection: any) {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: UI_CONTEXTMENU_OPEN, type: UI_CONTEXTMENU_OPEN,
uid, uid,
@ -51,7 +50,7 @@ export function openContextMenu(uid: string, selection: any) {
} }
export function increaseFontSize() { export function increaseFontSize() {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: UI_FONT_SIZE_INCR, type: UI_FONT_SIZE_INCR,
effect() { effect() {
@ -68,7 +67,7 @@ export function increaseFontSize() {
} }
export function decreaseFontSize() { export function decreaseFontSize() {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: UI_FONT_SIZE_DECR, type: UI_FONT_SIZE_DECR,
effect() { effect() {
@ -85,14 +84,14 @@ export function decreaseFontSize() {
}; };
} }
export function resetFontSize() { export function resetFontSize(): HyperActions {
return { return {
type: UI_FONT_SIZE_RESET type: UI_FONT_SIZE_RESET
}; };
} }
export function setFontSmoothing() { export function setFontSmoothing() {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
setTimeout(() => { setTimeout(() => {
const devicePixelRatio = window.devicePixelRatio; const devicePixelRatio = window.devicePixelRatio;
const fontSmoothing = devicePixelRatio < 2 ? 'subpixel-antialiased' : 'antialiased'; const fontSmoothing = devicePixelRatio < 2 ? 'subpixel-antialiased' : 'antialiased';
@ -105,7 +104,7 @@ export function setFontSmoothing() {
}; };
} }
export function windowGeometryUpdated() { export function windowGeometryUpdated(): HyperActions {
return { return {
type: UI_WINDOW_GEOMETRY_CHANGED type: UI_WINDOW_GEOMETRY_CHANGED
}; };
@ -135,8 +134,8 @@ const getNeighborIndex = (groups: string[], uid: string, type: string) => {
return (groups.indexOf(uid) + groups.length - 1) % groups.length; return (groups.indexOf(uid) + groups.length - 1) % groups.length;
}; };
function moveToNeighborPane(type: string) { function moveToNeighborPane(type: typeof UI_MOVE_NEXT_PANE | typeof UI_MOVE_PREV_PANE) {
return () => (dispatch: Dispatch<any>, getState: () => HyperState) => { return () => (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type, type,
effect() { effect() {
@ -152,7 +151,7 @@ function moveToNeighborPane(type: string) {
dispatch(setActiveSession(sessionUid!)); dispatch(setActiveSession(sessionUid!));
} }
} }
}); } as HyperActions);
}; };
} }
@ -165,7 +164,7 @@ const getGroupUids = (state: HyperState) => {
}; };
export function moveLeft() { export function moveLeft() {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: UI_MOVE_LEFT, type: UI_MOVE_LEFT,
effect() { effect() {
@ -186,7 +185,7 @@ export function moveLeft() {
} }
export function moveRight() { export function moveRight() {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({ dispatch({
type: UI_MOVE_RIGHT, type: UI_MOVE_RIGHT,
effect() { effect() {
@ -207,7 +206,7 @@ export function moveRight() {
} }
export function moveTo(i: number | 'last') { export function moveTo(i: number | 'last') {
return (dispatch: Dispatch<any>, getState: () => HyperState) => { return (dispatch: HyperDispatch, getState: () => HyperState) => {
if (i === 'last') { if (i === 'last') {
// Finding last tab index // Finding last tab index
const {termGroups} = getState().termGroups; const {termGroups} = getState().termGroups;
@ -238,7 +237,7 @@ export function moveTo(i: number | 'last') {
} }
export function windowMove(window: any) { export function windowMove(window: any) {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_WINDOW_MOVE, type: UI_WINDOW_MOVE,
window, window,
@ -250,7 +249,7 @@ export function windowMove(window: any) {
} }
export function windowGeometryChange() { export function windowGeometryChange() {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_WINDOW_MOVE, type: UI_WINDOW_MOVE,
effect() { effect() {
@ -261,7 +260,7 @@ export function windowGeometryChange() {
} }
export function openFile(path: string) { export function openFile(path: string) {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_OPEN_FILE, type: UI_OPEN_FILE,
effect() { effect() {
@ -288,20 +287,20 @@ export function openFile(path: string) {
}; };
} }
export function enterFullScreen() { export function enterFullScreen(): HyperActions {
return { return {
type: UI_ENTER_FULLSCREEN type: UI_ENTER_FULLSCREEN
}; };
} }
export function leaveFullScreen() { export function leaveFullScreen(): HyperActions {
return { return {
type: UI_LEAVE_FULLSCREEN type: UI_LEAVE_FULLSCREEN
}; };
} }
export function openSSH(url: string) { export function openSSH(url: string) {
return (dispatch: Dispatch<any>) => { return (dispatch: HyperDispatch) => {
dispatch({ dispatch({
type: UI_OPEN_SSH_URL, type: UI_OPEN_SSH_URL,
effect() { effect() {
@ -325,7 +324,7 @@ export function openSSH(url: string) {
} }
export function execCommand(command: any, fn: any, e: any) { export function execCommand(command: any, fn: any, e: any) {
return (dispatch: Dispatch<any>) => return (dispatch: HyperDispatch) =>
dispatch({ dispatch({
type: UI_COMMAND_EXEC, type: UI_COMMAND_EXEC,
command, command,

View file

@ -1,16 +1,17 @@
import {UPDATE_INSTALL, UPDATE_AVAILABLE} from '../constants/updater'; import {UPDATE_INSTALL, UPDATE_AVAILABLE} from '../constants/updater';
import rpc from '../rpc'; import rpc from '../rpc';
import {HyperActions} from '../hyper';
export function installUpdate() { export function installUpdate(): HyperActions {
return { return {
type: UPDATE_INSTALL, type: UPDATE_INSTALL,
effect: () => { effect: () => {
rpc.emit('quit and install'); rpc.emit('quit and install', null);
} }
}; };
} }
export function updateAvailable(version, notes, releaseUrl, canInstall) { export function updateAvailable(version: string, notes: string, releaseUrl: string, canInstall: boolean): HyperActions {
return { return {
type: UPDATE_AVAILABLE, type: UPDATE_AVAILABLE,
version, version,