mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
improve writing performance by avoiding redux for pty events
This commit is contained in:
parent
2412d3422a
commit
44dfb0faf8
5 changed files with 8 additions and 64 deletions
|
|
@ -1,19 +1,16 @@
|
|||
import rpc from '../rpc';
|
||||
import isUrl from '../utils/url-command';
|
||||
import {keys} from '../utils/object';
|
||||
import findBySession from '../utils/term-groups';
|
||||
import {
|
||||
SESSION_ADD,
|
||||
SESSION_RESIZE,
|
||||
SESSION_REQUEST,
|
||||
SESSION_ADD_DATA,
|
||||
SESSION_PTY_DATA,
|
||||
SESSION_PTY_EXIT,
|
||||
SESSION_USER_EXIT,
|
||||
SESSION_SET_ACTIVE,
|
||||
SESSION_CLEAR_ACTIVE,
|
||||
SESSION_USER_DATA,
|
||||
SESSION_URL_SET,
|
||||
SESSION_URL_UNSET,
|
||||
SESSION_SET_XTERM_TITLE
|
||||
} from '../constants/sessions';
|
||||
|
|
@ -48,30 +45,10 @@ export function requestSession() {
|
|||
}
|
||||
|
||||
export function addSessionData(uid, data) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: SESSION_ADD_DATA,
|
||||
data,
|
||||
effect() {
|
||||
const session = getState().sessions.sessions[uid];
|
||||
if (session) {
|
||||
const enterKey = data.indexOf('\n') > 0;
|
||||
const url = enterKey ? isUrl(session.shell, data) : null;
|
||||
if (url) {
|
||||
return dispatch({
|
||||
type: SESSION_URL_SET,
|
||||
uid,
|
||||
url
|
||||
});
|
||||
}
|
||||
}
|
||||
dispatch({
|
||||
type: SESSION_PTY_DATA,
|
||||
uid,
|
||||
data
|
||||
});
|
||||
}
|
||||
});
|
||||
return {
|
||||
type: SESSION_PTY_DATA,
|
||||
uid,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
20
lib/index.js
20
lib/index.js
|
|
@ -6,6 +6,7 @@ import {render} from 'react-dom';
|
|||
|
||||
import rpc from './rpc';
|
||||
import init from './actions/index';
|
||||
import terms from './terms';
|
||||
import * as config from './utils/config';
|
||||
import * as plugins from './utils/plugins';
|
||||
import * as uiActions from './actions/ui';
|
||||
|
|
@ -46,28 +47,11 @@ rpc.on('session add', data => {
|
|||
|
||||
// we aggregate all the incoming pty events by raf
|
||||
// debouncing, to reduce allocation and iterations
|
||||
let req;
|
||||
let objects = {};
|
||||
rpc.on('session data', d => {
|
||||
// the uid is a uuid v4 so it's 36 chars long
|
||||
const uid = d.slice(0, 36);
|
||||
const data = d.slice(36);
|
||||
if (objects[uid] === undefined) {
|
||||
objects[uid] = data;
|
||||
} else {
|
||||
objects[uid] += data;
|
||||
}
|
||||
if (!req) {
|
||||
req = requestAnimationFrame(() => {
|
||||
for (const i in objects) {
|
||||
if ({}.hasOwnProperty.call(objects, i)) {
|
||||
store_.dispatch(sessionActions.addSessionData(i, objects[i]));
|
||||
}
|
||||
}
|
||||
objects = {};
|
||||
req = null;
|
||||
});
|
||||
}
|
||||
terms[uid].term.write(data);
|
||||
});
|
||||
|
||||
rpc.on('session data send', ({uid, data, escaped}) => {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {createLogger} from 'redux-logger';
|
|||
import rootReducer from '../reducers/index';
|
||||
import effects from '../utils/effects';
|
||||
import * as plugins from '../utils/plugins';
|
||||
import writeMiddleware from './write-middleware';
|
||||
|
||||
export default () => {
|
||||
const logger = createLogger({
|
||||
|
|
@ -13,7 +12,7 @@ export default () => {
|
|||
});
|
||||
|
||||
const enhancer = compose(
|
||||
applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware, logger),
|
||||
applyMiddleware(thunk, plugins.middleware, thunk, effects, logger),
|
||||
window.devToolsExtension()
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,5 @@ 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';
|
||||
|
||||
export default () =>
|
||||
createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware));
|
||||
export default () => createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects));
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
import terms from '../terms';
|
||||
|
||||
// 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 => {
|
||||
if (action.type === 'SESSION_PTY_DATA') {
|
||||
const term = terms[action.uid];
|
||||
if (term) {
|
||||
term.write(action.data);
|
||||
}
|
||||
}
|
||||
next(action);
|
||||
};
|
||||
Loading…
Reference in a new issue