diff --git a/lib/hyper.d.ts b/lib/hyper.d.ts index a1908699..544c9fff 100644 --- a/lib/hyper.d.ts +++ b/lib/hyper.d.ts @@ -180,6 +180,11 @@ export type HyperActions = ( type immutableRecord = {[k in keyof T]: Immutable}; +import {ThunkDispatch} from 'redux-thunk'; +import configureStore from './store/configure-store'; +export type HyperThunkDispatch = ThunkDispatch; +export type HyperDispatch = ReturnType['dispatch']; + export type TermsProps = { activeRootGroup: string | null; activeSession: string | null; diff --git a/lib/store/configure-store.dev.ts b/lib/store/configure-store.dev.ts index 36b87755..abc40937 100644 --- a/lib/store/configure-store.dev.ts +++ b/lib/store/configure-store.dev.ts @@ -1,14 +1,15 @@ -import {createStore, applyMiddleware, compose} from 'redux'; +import {createStore, applyMiddleware} from 'redux'; import thunk from 'redux-thunk'; import rootReducer from '../reducers/index'; import effects from '../utils/effects'; import * as plugins from '../utils/plugins'; import writeMiddleware from './write-middleware'; +import {composeWithDevTools} from 'redux-devtools-extension'; +import {HyperState, HyperThunkDispatch} from '../hyper'; export default () => { - const enhancer = compose( - applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects), - window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() + const enhancer = composeWithDevTools( + applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects) ); return createStore(rootReducer, enhancer); diff --git a/lib/store/configure-store.prod.ts b/lib/store/configure-store.prod.ts index c7a5a3ce..fbfae9c6 100644 --- a/lib/store/configure-store.prod.ts +++ b/lib/store/configure-store.prod.ts @@ -4,6 +4,10 @@ import rootReducer from '../reducers/index'; import effects from '../utils/effects'; import * as plugins from '../utils/plugins'; import writeMiddleware from './write-middleware'; +import {HyperState, HyperThunkDispatch} from '../hyper'; export default () => - createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects)); + createStore( + rootReducer, + applyMiddleware(thunk, plugins.middleware, thunk, writeMiddleware, effects) + ); diff --git a/lib/store/write-middleware.ts b/lib/store/write-middleware.ts index 70b505e9..a13fdd93 100644 --- a/lib/store/write-middleware.ts +++ b/lib/store/write-middleware.ts @@ -1,9 +1,10 @@ import terms from '../terms'; +import {Middleware} from 'redux'; // the only side effect we perform from middleware // is to write to the react term instance directly // to avoid a performance hit -export default () => next => action => { +const writeMiddleware: Middleware = () => next => action => { if (action.type === 'SESSION_PTY_DATA') { const term = terms[action.uid]; if (term) { @@ -12,3 +13,5 @@ export default () => next => action => { } next(action); }; + +export default writeMiddleware; diff --git a/lib/terms.ts b/lib/terms.ts index ce4b6ad4..1a3aa82e 100644 --- a/lib/terms.ts +++ b/lib/terms.ts @@ -1,3 +1,5 @@ +import Term from './components/term'; + // react Term components add themselves // to this object upon mounting / unmounting // this is to allow imperative access to the @@ -5,5 +7,5 @@ // optimization for the most common action // within the system -const terms = {}; +const terms: Record = {}; export default terms; diff --git a/lib/utils/effects.ts b/lib/utils/effects.ts index 88b2b7a3..ae0bddb8 100644 --- a/lib/utils/effects.ts +++ b/lib/utils/effects.ts @@ -6,8 +6,8 @@ * defer or add to existing side effects at will * as the result of an action being triggered. */ - -export default () => (next: (arg0: any) => any) => (action: {effect: () => void}) => { +import {Middleware} from 'redux'; +const effectsMiddleware: Middleware = () => next => action => { const ret = next(action); if (action.effect) { action.effect(); @@ -15,3 +15,4 @@ export default () => (next: (arg0: any) => any) => (action: {effect: () => void} } return ret; }; +export default effectsMiddleware; diff --git a/lib/utils/plugins.ts b/lib/utils/plugins.ts index 11fb6f4e..f7312d2e 100644 --- a/lib/utils/plugins.ts +++ b/lib/utils/plugins.ts @@ -12,7 +12,7 @@ import ReactDOM from 'react-dom'; import Notification from '../components/notification'; import notify from './notify'; import {hyperPlugin, IUiReducer, ISessionReducer, ITermGroupReducer, HyperState} from '../hyper'; -import {Dispatch} from 'redux'; +import {Dispatch, Middleware} from 'redux'; // remote interface to `../plugins` const plugins = remote.require('./plugins') as typeof import('../../app/plugins'); @@ -539,8 +539,8 @@ export function decorateSessionsReducer(fn: ISessionReducer) { } // redux middleware generator -export const middleware = (store: any) => (next: any) => (action: any) => { - const nextMiddleware = (remaining: any[]) => (action_: any) => +export const middleware: Middleware = store => next => action => { + const nextMiddleware = (remaining: Middleware[]) => (action_: any) => remaining.length ? remaining[0](store)(nextMiddleware(remaining.slice(1)))(action_) : next(action_); nextMiddleware(middlewares)(action); }; diff --git a/package.json b/package.json index f5476dae..15cb4158 100644 --- a/package.json +++ b/package.json @@ -110,6 +110,7 @@ "plist": "3.0.1", "prettier": "1.19.1", "proxyquire": "2.1.3", + "redux-devtools-extension": "2.13.8", "spectron": "9.0.0", "style-loader": "1.1.2", "ts-node": "8.5.4", diff --git a/yarn.lock b/yarn.lock index 5b6243bf..f1adbad0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7103,6 +7103,11 @@ redent@^2.0.0: indent-string "^3.0.0" strip-indent "^2.0.0" +redux-devtools-extension@2.13.8: + version "2.13.8" + resolved "https://registry.yarnpkg.com/redux-devtools-extension/-/redux-devtools-extension-2.13.8.tgz#37b982688626e5e4993ff87220c9bbb7cd2d96e1" + integrity sha512-8qlpooP2QqPtZHQZRhx3x3OP5skEV1py/zUdMY28WNAocbafxdG2tRD1MWE7sp8obGMNYuLWanhhQ7EQvT1FBg== + redux-thunk@2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"