mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 05:38: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';
|
import {Immutable} from 'seamless-immutable';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
@ -26,10 +25,8 @@ export type ITermState = {
|
||||||
activeRootGroup: string | null;
|
activeRootGroup: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ITermGroupReducer = Reducer<Immutable<ITermState>, any>;
|
|
||||||
|
|
||||||
export type uiState = {
|
export type uiState = {
|
||||||
_lastUpdate: null;
|
_lastUpdate: number | null;
|
||||||
activeUid: string | null;
|
activeUid: string | null;
|
||||||
activityMarkers: Record<string, boolean>;
|
activityMarkers: Record<string, boolean>;
|
||||||
backgroundColor: string;
|
backgroundColor: string;
|
||||||
|
|
@ -77,8 +74,8 @@ export type uiState = {
|
||||||
macOptionSelectionMode: string;
|
macOptionSelectionMode: string;
|
||||||
maximized: boolean;
|
maximized: boolean;
|
||||||
messageDismissable: null | boolean;
|
messageDismissable: null | boolean;
|
||||||
messageText: null;
|
messageText: string | null;
|
||||||
messageURL: null;
|
messageURL: string | null;
|
||||||
modifierKeys: {
|
modifierKeys: {
|
||||||
altIsMeta: boolean;
|
altIsMeta: boolean;
|
||||||
cmdIsMeta: boolean;
|
cmdIsMeta: boolean;
|
||||||
|
|
@ -107,7 +104,6 @@ export type uiState = {
|
||||||
webGLRenderer: boolean;
|
webGLRenderer: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IUiReducer = Reducer<Immutable<uiState>>;
|
|
||||||
export type session = {
|
export type session = {
|
||||||
cleared: boolean;
|
cleared: boolean;
|
||||||
cols: number | null;
|
cols: number | null;
|
||||||
|
|
@ -115,7 +111,7 @@ export type session = {
|
||||||
resizeAt?: number;
|
resizeAt?: number;
|
||||||
rows: number | null;
|
rows: number | null;
|
||||||
search: boolean;
|
search: boolean;
|
||||||
shell: string;
|
shell: string | null;
|
||||||
title: string;
|
title: string;
|
||||||
uid: string;
|
uid: string;
|
||||||
url: string | null;
|
url: string | null;
|
||||||
|
|
@ -128,7 +124,14 @@ export type sessionState = {
|
||||||
write?: any;
|
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 = {
|
export type hyperPlugin = {
|
||||||
getTabProps: any;
|
getTabProps: any;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,17 @@
|
||||||
import {combineReducers} from 'redux';
|
import {combineReducers} from 'redux';
|
||||||
import ui from './ui';
|
import ui, {IUiReducer} from './ui';
|
||||||
import sessions from './sessions';
|
import sessions, {ISessionReducer} from './sessions';
|
||||||
import termGroups from './term-groups';
|
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,
|
ui,
|
||||||
sessions,
|
sessions,
|
||||||
termGroups
|
termGroups
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import {
|
||||||
SESSION_SEARCH,
|
SESSION_SEARCH,
|
||||||
SESSION_SEARCH_CLOSE
|
SESSION_SEARCH_CLOSE
|
||||||
} from '../constants/sessions';
|
} from '../constants/sessions';
|
||||||
import {sessionState, session} from '../hyper';
|
import {sessionState, session, HyperActions} from '../hyper';
|
||||||
|
|
||||||
const initialState: ImmutableType<sessionState> = Immutable({
|
const initialState: ImmutableType<sessionState> = Immutable({
|
||||||
sessions: {},
|
sessions: {},
|
||||||
|
|
@ -36,14 +36,14 @@ function Session(obj: Immutable.DeepPartial<session>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteSession(state: ImmutableType<sessionState>, uid: string) {
|
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();
|
const sessions_ = sessions.asMutable();
|
||||||
delete sessions_[uid];
|
delete sessions_[uid];
|
||||||
return sessions_;
|
return sessions_;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const reducer = (state: ImmutableType<sessionState> = initialState, action: any) => {
|
const reducer = (state: ImmutableType<sessionState> = initialState, action: HyperActions) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SESSION_ADD:
|
case SESSION_ADD:
|
||||||
return state.set('activeUid', action.uid).setIn(
|
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);
|
export default decorateSessionsReducer(reducer);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import uuid from 'uuid';
|
import uuid from 'uuid';
|
||||||
import Immutable, {Immutable as ImmutableType} from 'seamless-immutable';
|
import Immutable, {Immutable as ImmutableType} from 'seamless-immutable';
|
||||||
import {TERM_GROUP_EXIT, TERM_GROUP_RESIZE} from '../constants/term-groups';
|
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 findBySession from '../utils/term-groups';
|
||||||
import {decorateTermGroupsReducer} from '../utils/plugins';
|
import {decorateTermGroupsReducer} from '../utils/plugins';
|
||||||
import {ITermGroup, ITermState, ITermGroups} from '../hyper';
|
import {ITermGroup, ITermState, ITermGroups, HyperActions} from '../hyper';
|
||||||
|
|
||||||
const MIN_SIZE = 0.05;
|
const MIN_SIZE = 0.05;
|
||||||
const initialState = Immutable<ITermState>({
|
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 {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
|
// 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 -
|
// group's parent - or if it's the first split for that group -
|
||||||
// we want the parent to get another child:
|
// 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);
|
return state.setIn(['termGroups', uid, 'sizes'], sizes);
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducer = (
|
const reducer = (state = initialState, action: HyperActions) => {
|
||||||
state = initialState,
|
|
||||||
action: {
|
|
||||||
splitDirection: any;
|
|
||||||
uid: any;
|
|
||||||
activeUid: any;
|
|
||||||
type: any;
|
|
||||||
sizes: any;
|
|
||||||
}
|
|
||||||
) => {
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SESSION_ADD: {
|
case SESSION_ADD: {
|
||||||
if (action.splitDirection) {
|
if (action.splitDirection) {
|
||||||
|
|
@ -236,4 +227,6 @@ const reducer = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ITermGroupReducer = typeof reducer;
|
||||||
|
|
||||||
export default decorateTermGroupsReducer(reducer);
|
export default decorateTermGroupsReducer(reducer);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import {
|
||||||
SESSION_SET_CWD
|
SESSION_SET_CWD
|
||||||
} from '../constants/sessions';
|
} from '../constants/sessions';
|
||||||
import {UPDATE_AVAILABLE} from '../constants/updater';
|
import {UPDATE_AVAILABLE} from '../constants/updater';
|
||||||
import {uiState} from '../hyper';
|
import {uiState, HyperActions} from '../hyper';
|
||||||
|
|
||||||
const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
|
const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
|
||||||
const allowedCursorBlinkValues = new Set([true, false]);
|
const allowedCursorBlinkValues = new Set([true, false]);
|
||||||
|
|
@ -114,7 +114,7 @@ const initial: ImmutableType<uiState> = Immutable({
|
||||||
|
|
||||||
const currentWindow = remote.getCurrentWindow();
|
const currentWindow = remote.getCurrentWindow();
|
||||||
|
|
||||||
const reducer = (state = initial, action: any) => {
|
const reducer = (state = initial, action: HyperActions) => {
|
||||||
let state_ = state;
|
let state_ = state;
|
||||||
let isMax;
|
let isMax;
|
||||||
//eslint-disable-next-line default-case
|
//eslint-disable-next-line default-case
|
||||||
|
|
@ -450,4 +450,6 @@ const reducer = (state = initial, action: any) => {
|
||||||
return state_;
|
return state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IUiReducer = typeof reducer;
|
||||||
|
|
||||||
export default decorateUIReducer(reducer);
|
export default decorateUIReducer(reducer);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue