mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 13:48:41 -09:00
Move Date.now() into actions to have pure reducers (#2324)
Reducers shouldn't have side effect. Date.now() is a side effect and should be done in action creators.
This commit is contained in:
parent
2d14b19dcd
commit
d3a015466a
3 changed files with 13 additions and 10 deletions
|
|
@ -21,6 +21,7 @@ import {
|
||||||
export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
|
export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const {sessions} = getState();
|
const {sessions} = getState();
|
||||||
|
const now = Date.now();
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SESSION_ADD,
|
type: SESSION_ADD,
|
||||||
uid,
|
uid,
|
||||||
|
|
@ -29,7 +30,8 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
|
||||||
cols,
|
cols,
|
||||||
rows,
|
rows,
|
||||||
splitDirection,
|
splitDirection,
|
||||||
activeUid: sessions.activeUid
|
activeUid: sessions.activeUid,
|
||||||
|
now
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -54,6 +56,7 @@ export function addSessionData(uid, data) {
|
||||||
data,
|
data,
|
||||||
effect() {
|
effect() {
|
||||||
const session = getState().sessions.sessions[uid];
|
const session = getState().sessions.sessions[uid];
|
||||||
|
const now = Date.now();
|
||||||
if (session) {
|
if (session) {
|
||||||
const enterKey = data.indexOf('\n') > 0;
|
const enterKey = data.indexOf('\n') > 0;
|
||||||
const url = enterKey ? isUrl(session.shell, data) : null;
|
const url = enterKey ? isUrl(session.shell, data) : null;
|
||||||
|
|
@ -68,7 +71,8 @@ export function addSessionData(uid, data) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SESSION_PTY_DATA,
|
type: SESSION_PTY_DATA,
|
||||||
uid,
|
uid,
|
||||||
data
|
data,
|
||||||
|
now
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -127,12 +131,14 @@ export function resizeSession(uid, cols, rows) {
|
||||||
const {termGroups} = getState();
|
const {termGroups} = getState();
|
||||||
const group = findBySession(termGroups, uid);
|
const group = findBySession(termGroups, uid);
|
||||||
const isStandaloneTerm = !group.parentUid && !group.children.length;
|
const isStandaloneTerm = !group.parentUid && !group.children.length;
|
||||||
|
const now = Date.now();
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SESSION_RESIZE,
|
type: SESSION_RESIZE,
|
||||||
uid,
|
uid,
|
||||||
cols,
|
cols,
|
||||||
rows,
|
rows,
|
||||||
isStandaloneTerm,
|
isStandaloneTerm,
|
||||||
|
now,
|
||||||
effect() {
|
effect() {
|
||||||
rpc.emit('resize', {uid, cols, rows});
|
rpc.emit('resize', {uid, cols, rows});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ const reducer = (state = initialState, action) => {
|
||||||
return state.setIn(['sessions', action.uid], state.sessions[action.uid].merge({
|
return state.setIn(['sessions', action.uid], state.sessions[action.uid].merge({
|
||||||
rows: action.rows,
|
rows: action.rows,
|
||||||
cols: action.cols,
|
cols: action.cols,
|
||||||
resizeAt: Date.now()
|
resizeAt: action.now
|
||||||
}));
|
}));
|
||||||
|
|
||||||
case SESSION_SET_CWD:
|
case SESSION_SET_CWD:
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ const reducer = (state = initial, action) => {
|
||||||
state_ = state.merge({
|
state_ = state.merge({
|
||||||
activeUid: action.uid,
|
activeUid: action.uid,
|
||||||
openAt: {
|
openAt: {
|
||||||
[action.uid]: Date.now()
|
[action.uid]: action.now
|
||||||
}
|
}
|
||||||
}, {deep: true});
|
}, {deep: true});
|
||||||
break;
|
break;
|
||||||
|
|
@ -231,7 +231,7 @@ const reducer = (state = initial, action) => {
|
||||||
state_ = state.merge({
|
state_ = state.merge({
|
||||||
rows: action.rows,
|
rows: action.rows,
|
||||||
cols: action.cols,
|
cols: action.cols,
|
||||||
resizeAt: Date.now()
|
resizeAt: action.now
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -264,11 +264,8 @@ const reducer = (state = initial, action) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// current time for comparisons
|
|
||||||
const now = Date.now();
|
|
||||||
|
|
||||||
// if first data events after open, ignore
|
// if first data events after open, ignore
|
||||||
if (now - state.openAt[action.uid] < 1000) {
|
if (action.now - state.openAt[action.uid] < 1000) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,7 +273,7 @@ const reducer = (state = initial, action) => {
|
||||||
// proximity of a resize event, since we
|
// proximity of a resize event, since we
|
||||||
// expect to get data packets from the resize
|
// expect to get data packets from the resize
|
||||||
// of the ptys as a result
|
// of the ptys as a result
|
||||||
if (!state.resizeAt || now - state.resizeAt > 1000) {
|
if (!state.resizeAt || action.now - state.resizeAt > 1000) {
|
||||||
state_ = state.merge({
|
state_ = state.merge({
|
||||||
activityMarkers: {
|
activityMarkers: {
|
||||||
[action.uid]: true
|
[action.uid]: true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue