mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 21:28:40 -09:00
Revert "improve writing performance by avoiding redux for pty events"
This reverts commit 44dfb0faf8.
This commit is contained in:
parent
56a4ab26bb
commit
b775e23c3c
5 changed files with 64 additions and 8 deletions
|
|
@ -1,16 +1,19 @@
|
||||||
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';
|
||||||
|
|
@ -45,10 +48,30 @@ export function requestSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addSessionData(uid, data) {
|
export function addSessionData(uid, data) {
|
||||||
return {
|
return (dispatch, getState) => {
|
||||||
type: SESSION_PTY_DATA,
|
dispatch({
|
||||||
uid,
|
type: SESSION_ADD_DATA,
|
||||||
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,7 +6,6 @@ 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';
|
||||||
|
|
@ -47,11 +46,28 @@ 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);
|
||||||
terms[uid].term.write(data);
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rpc.on('session data send', ({uid, data, escaped}) => {
|
rpc.on('session data send', ({uid, data, escaped}) => {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ 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({
|
||||||
|
|
@ -12,7 +13,7 @@ export default () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const enhancer = compose(
|
const enhancer = compose(
|
||||||
applyMiddleware(thunk, plugins.middleware, thunk, effects, logger),
|
applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware, logger),
|
||||||
window.devToolsExtension()
|
window.devToolsExtension()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,7 @@ 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 () => createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects));
|
export default () =>
|
||||||
|
createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware));
|
||||||
|
|
|
||||||
14
lib/store/write-middleware.js
Normal file
14
lib/store/write-middleware.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
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