mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 21:58:39 -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 rpc from '../rpc';
|
||||||
import isUrl from '../utils/url-command';
|
|
||||||
import {keys} from '../utils/object';
|
import {keys} from '../utils/object';
|
||||||
import findBySession from '../utils/term-groups';
|
import findBySession from '../utils/term-groups';
|
||||||
import {
|
import {
|
||||||
SESSION_ADD,
|
SESSION_ADD,
|
||||||
SESSION_RESIZE,
|
SESSION_RESIZE,
|
||||||
SESSION_REQUEST,
|
SESSION_REQUEST,
|
||||||
SESSION_ADD_DATA,
|
|
||||||
SESSION_PTY_DATA,
|
SESSION_PTY_DATA,
|
||||||
SESSION_PTY_EXIT,
|
SESSION_PTY_EXIT,
|
||||||
SESSION_USER_EXIT,
|
SESSION_USER_EXIT,
|
||||||
SESSION_SET_ACTIVE,
|
SESSION_SET_ACTIVE,
|
||||||
SESSION_CLEAR_ACTIVE,
|
SESSION_CLEAR_ACTIVE,
|
||||||
SESSION_USER_DATA,
|
SESSION_USER_DATA,
|
||||||
SESSION_URL_SET,
|
|
||||||
SESSION_URL_UNSET,
|
SESSION_URL_UNSET,
|
||||||
SESSION_SET_XTERM_TITLE
|
SESSION_SET_XTERM_TITLE
|
||||||
} from '../constants/sessions';
|
} from '../constants/sessions';
|
||||||
|
|
@ -48,30 +45,10 @@ export function requestSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addSessionData(uid, data) {
|
export function addSessionData(uid, data) {
|
||||||
return (dispatch, getState) => {
|
return {
|
||||||
dispatch({
|
type: SESSION_PTY_DATA,
|
||||||
type: SESSION_ADD_DATA,
|
uid,
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
20
lib/index.js
20
lib/index.js
|
|
@ -6,6 +6,7 @@ import {render} from 'react-dom';
|
||||||
|
|
||||||
import rpc from './rpc';
|
import rpc from './rpc';
|
||||||
import init from './actions/index';
|
import init from './actions/index';
|
||||||
|
import terms from './terms';
|
||||||
import * as config from './utils/config';
|
import * as config from './utils/config';
|
||||||
import * as plugins from './utils/plugins';
|
import * as plugins from './utils/plugins';
|
||||||
import * as uiActions from './actions/ui';
|
import * as uiActions from './actions/ui';
|
||||||
|
|
@ -46,28 +47,11 @@ rpc.on('session add', data => {
|
||||||
|
|
||||||
// we aggregate all the incoming pty events by raf
|
// we aggregate all the incoming pty events by raf
|
||||||
// debouncing, to reduce allocation and iterations
|
// debouncing, to reduce allocation and iterations
|
||||||
let req;
|
|
||||||
let objects = {};
|
|
||||||
rpc.on('session data', d => {
|
rpc.on('session data', d => {
|
||||||
// the uid is a uuid v4 so it's 36 chars long
|
// the uid is a uuid v4 so it's 36 chars long
|
||||||
const uid = d.slice(0, 36);
|
const uid = d.slice(0, 36);
|
||||||
const data = d.slice(36);
|
const data = d.slice(36);
|
||||||
if (objects[uid] === undefined) {
|
terms[uid].term.write(data);
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rpc.on('session data send', ({uid, data, escaped}) => {
|
rpc.on('session data send', ({uid, data, escaped}) => {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {createLogger} from 'redux-logger';
|
||||||
import rootReducer from '../reducers/index';
|
import rootReducer from '../reducers/index';
|
||||||
import effects from '../utils/effects';
|
import effects from '../utils/effects';
|
||||||
import * as plugins from '../utils/plugins';
|
import * as plugins from '../utils/plugins';
|
||||||
import writeMiddleware from './write-middleware';
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const logger = createLogger({
|
const logger = createLogger({
|
||||||
|
|
@ -13,7 +12,7 @@ export default () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const enhancer = compose(
|
const enhancer = compose(
|
||||||
applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware, logger),
|
applyMiddleware(thunk, plugins.middleware, thunk, effects, logger),
|
||||||
window.devToolsExtension()
|
window.devToolsExtension()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,5 @@ import thunk from 'redux-thunk';
|
||||||
import rootReducer from '../reducers/index';
|
import rootReducer from '../reducers/index';
|
||||||
import effects from '../utils/effects';
|
import effects from '../utils/effects';
|
||||||
import * as plugins from '../utils/plugins';
|
import * as plugins from '../utils/plugins';
|
||||||
import writeMiddleware from './write-middleware';
|
|
||||||
|
|
||||||
export default () =>
|
export default () => createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects));
|
||||||
createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware));
|
|
||||||
|
|
|
||||||
|
|
@ -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