2023-06-26 01:29:50 -08:00
|
|
|
import type {HyperActions, HyperState} from '../hyper';
|
2017-09-25 03:55:04 -08:00
|
|
|
import terms from '../terms';
|
2023-06-26 01:29:50 -08:00
|
|
|
import type {Dispatch, Middleware} from 'redux';
|
2017-09-25 03:55:04 -08:00
|
|
|
|
|
|
|
|
// the only side effect we perform from middleware
|
|
|
|
|
// is to write to the react term instance directly
|
|
|
|
|
// to avoid a performance hit
|
2023-06-25 04:27:42 -08:00
|
|
|
const writeMiddleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = () => (next) => (action: HyperActions) => {
|
2017-09-25 03:55:04 -08:00
|
|
|
if (action.type === 'SESSION_PTY_DATA') {
|
|
|
|
|
const term = terms[action.uid];
|
|
|
|
|
if (term) {
|
2017-09-25 04:44:43 -08:00
|
|
|
term.term.write(action.data);
|
2017-09-25 03:55:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
next(action);
|
|
|
|
|
};
|
2020-01-02 08:49:57 -09:00
|
|
|
|
|
|
|
|
export default writeMiddleware;
|