mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
improve reducer typings
This commit is contained in:
parent
38c534b3aa
commit
c71b24ebea
5 changed files with 40 additions and 32 deletions
21
lib/hyper.d.ts
vendored
21
lib/hyper.d.ts
vendored
|
|
@ -1,4 +1,3 @@
|
|||
import {Reducer} from 'redux';
|
||||
import {Immutable} from 'seamless-immutable';
|
||||
|
||||
declare global {
|
||||
|
|
@ -26,10 +25,8 @@ export type ITermState = {
|
|||
activeRootGroup: string | null;
|
||||
};
|
||||
|
||||
export type ITermGroupReducer = Reducer<Immutable<ITermState>, any>;
|
||||
|
||||
export type uiState = {
|
||||
_lastUpdate: null;
|
||||
_lastUpdate: number | null;
|
||||
activeUid: string | null;
|
||||
activityMarkers: Record<string, boolean>;
|
||||
backgroundColor: string;
|
||||
|
|
@ -77,8 +74,8 @@ export type uiState = {
|
|||
macOptionSelectionMode: string;
|
||||
maximized: boolean;
|
||||
messageDismissable: null | boolean;
|
||||
messageText: null;
|
||||
messageURL: null;
|
||||
messageText: string | null;
|
||||
messageURL: string | null;
|
||||
modifierKeys: {
|
||||
altIsMeta: boolean;
|
||||
cmdIsMeta: boolean;
|
||||
|
|
@ -107,7 +104,6 @@ export type uiState = {
|
|||
webGLRenderer: boolean;
|
||||
};
|
||||
|
||||
export type IUiReducer = Reducer<Immutable<uiState>>;
|
||||
export type session = {
|
||||
cleared: boolean;
|
||||
cols: number | null;
|
||||
|
|
@ -115,7 +111,7 @@ export type session = {
|
|||
resizeAt?: number;
|
||||
rows: number | null;
|
||||
search: boolean;
|
||||
shell: string;
|
||||
shell: string | null;
|
||||
title: string;
|
||||
uid: string;
|
||||
url: string | null;
|
||||
|
|
@ -128,7 +124,14 @@ export type sessionState = {
|
|||
write?: any;
|
||||
};
|
||||
|
||||
export type ISessionReducer = Reducer<Immutable<sessionState>>;
|
||||
export {ITermGroupReducer} from './reducers/term-groups';
|
||||
import {ITermGroupReducer} from './reducers/term-groups';
|
||||
|
||||
export {IUiReducer} from './reducers/ui';
|
||||
import {IUiReducer} from './reducers/ui';
|
||||
|
||||
export {ISessionReducer} from './reducers/sessions';
|
||||
import {ISessionReducer} from './reducers/sessions';
|
||||
|
||||
export type hyperPlugin = {
|
||||
getTabProps: any;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,17 @@
|
|||
import {combineReducers} from 'redux';
|
||||
import ui from './ui';
|
||||
import sessions from './sessions';
|
||||
import termGroups from './term-groups';
|
||||
import ui, {IUiReducer} from './ui';
|
||||
import sessions, {ISessionReducer} from './sessions';
|
||||
import termGroups, {ITermGroupReducer} from './term-groups';
|
||||
import {HyperActions} from '../hyper';
|
||||
|
||||
export default combineReducers({
|
||||
export default combineReducers<
|
||||
{
|
||||
ui: ReturnType<IUiReducer>;
|
||||
sessions: ReturnType<ISessionReducer>;
|
||||
termGroups: ReturnType<ITermGroupReducer>;
|
||||
},
|
||||
HyperActions
|
||||
>({
|
||||
ui,
|
||||
sessions,
|
||||
termGroups
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
SESSION_SEARCH,
|
||||
SESSION_SEARCH_CLOSE
|
||||
} from '../constants/sessions';
|
||||
import {sessionState, session} from '../hyper';
|
||||
import {sessionState, session, HyperActions} from '../hyper';
|
||||
|
||||
const initialState: ImmutableType<sessionState> = Immutable({
|
||||
sessions: {},
|
||||
|
|
@ -36,14 +36,14 @@ function Session(obj: Immutable.DeepPartial<session>) {
|
|||
}
|
||||
|
||||
function deleteSession(state: ImmutableType<sessionState>, uid: string) {
|
||||
return state.updateIn(['sessions'], (sessions: ImmutableType<any>) => {
|
||||
return state.updateIn(['sessions'], (sessions: typeof state['sessions']) => {
|
||||
const sessions_ = sessions.asMutable();
|
||||
delete sessions_[uid];
|
||||
return sessions_;
|
||||
});
|
||||
}
|
||||
|
||||
const reducer = (state: ImmutableType<sessionState> = initialState, action: any) => {
|
||||
const reducer = (state: ImmutableType<sessionState> = initialState, action: HyperActions) => {
|
||||
switch (action.type) {
|
||||
case SESSION_ADD:
|
||||
return state.set('activeUid', action.uid).setIn(
|
||||
|
|
@ -135,4 +135,6 @@ const reducer = (state: ImmutableType<sessionState> = initialState, action: any)
|
|||
}
|
||||
};
|
||||
|
||||
export type ISessionReducer = typeof reducer;
|
||||
|
||||
export default decorateSessionsReducer(reducer);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import uuid from 'uuid';
|
||||
import Immutable, {Immutable as ImmutableType} from 'seamless-immutable';
|
||||
import {TERM_GROUP_EXIT, TERM_GROUP_RESIZE} from '../constants/term-groups';
|
||||
import {SESSION_ADD, SESSION_SET_ACTIVE} from '../constants/sessions';
|
||||
import {SESSION_ADD, SESSION_SET_ACTIVE, SessionAddAction} from '../constants/sessions';
|
||||
import findBySession from '../utils/term-groups';
|
||||
import {decorateTermGroupsReducer} from '../utils/plugins';
|
||||
import {ITermGroup, ITermState, ITermGroups} from '../hyper';
|
||||
import {ITermGroup, ITermState, ITermGroups, HyperActions} from '../hyper';
|
||||
|
||||
const MIN_SIZE = 0.05;
|
||||
const initialState = Immutable<ITermState>({
|
||||
|
|
@ -66,9 +66,9 @@ const removalRebalance = (oldSizes: ImmutableType<number[]>, index: number) => {
|
|||
);
|
||||
};
|
||||
|
||||
const splitGroup = (state: ImmutableType<ITermState>, action: {splitDirection: any; uid: string; activeUid: any}) => {
|
||||
const splitGroup = (state: ImmutableType<ITermState>, action: SessionAddAction) => {
|
||||
const {splitDirection, uid, activeUid} = action;
|
||||
const activeGroup = findBySession(state, activeUid)!;
|
||||
const activeGroup = findBySession(state, activeUid!)!;
|
||||
// If we're splitting in the same direction as the current active
|
||||
// group's parent - or if it's the first split for that group -
|
||||
// we want the parent to get another child:
|
||||
|
|
@ -197,16 +197,7 @@ const resizeGroup = (state: ImmutableType<ITermState>, uid: any, sizes: number[]
|
|||
return state.setIn(['termGroups', uid, 'sizes'], sizes);
|
||||
};
|
||||
|
||||
const reducer = (
|
||||
state = initialState,
|
||||
action: {
|
||||
splitDirection: any;
|
||||
uid: any;
|
||||
activeUid: any;
|
||||
type: any;
|
||||
sizes: any;
|
||||
}
|
||||
) => {
|
||||
const reducer = (state = initialState, action: HyperActions) => {
|
||||
switch (action.type) {
|
||||
case SESSION_ADD: {
|
||||
if (action.splitDirection) {
|
||||
|
|
@ -236,4 +227,6 @@ const reducer = (
|
|||
}
|
||||
};
|
||||
|
||||
export type ITermGroupReducer = typeof reducer;
|
||||
|
||||
export default decorateTermGroupsReducer(reducer);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import {
|
|||
SESSION_SET_CWD
|
||||
} from '../constants/sessions';
|
||||
import {UPDATE_AVAILABLE} from '../constants/updater';
|
||||
import {uiState} from '../hyper';
|
||||
import {uiState, HyperActions} from '../hyper';
|
||||
|
||||
const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
|
||||
const allowedCursorBlinkValues = new Set([true, false]);
|
||||
|
|
@ -114,7 +114,7 @@ const initial: ImmutableType<uiState> = Immutable({
|
|||
|
||||
const currentWindow = remote.getCurrentWindow();
|
||||
|
||||
const reducer = (state = initial, action: any) => {
|
||||
const reducer = (state = initial, action: HyperActions) => {
|
||||
let state_ = state;
|
||||
let isMax;
|
||||
//eslint-disable-next-line default-case
|
||||
|
|
@ -450,4 +450,6 @@ const reducer = (state = initial, action: any) => {
|
|||
return state_;
|
||||
};
|
||||
|
||||
export type IUiReducer = typeof reducer;
|
||||
|
||||
export default decorateUIReducer(reducer);
|
||||
|
|
|
|||
Loading…
Reference in a new issue