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}) {
|
||||
return (dispatch, getState) => {
|
||||
const {sessions} = getState();
|
||||
const now = Date.now();
|
||||
dispatch({
|
||||
type: SESSION_ADD,
|
||||
uid,
|
||||
|
|
@ -29,7 +30,8 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
|
|||
cols,
|
||||
rows,
|
||||
splitDirection,
|
||||
activeUid: sessions.activeUid
|
||||
activeUid: sessions.activeUid,
|
||||
now
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
@ -54,6 +56,7 @@ export function addSessionData(uid, data) {
|
|||
data,
|
||||
effect() {
|
||||
const session = getState().sessions.sessions[uid];
|
||||
const now = Date.now();
|
||||
if (session) {
|
||||
const enterKey = data.indexOf('\n') > 0;
|
||||
const url = enterKey ? isUrl(session.shell, data) : null;
|
||||
|
|
@ -68,7 +71,8 @@ export function addSessionData(uid, data) {
|
|||
dispatch({
|
||||
type: SESSION_PTY_DATA,
|
||||
uid,
|
||||
data
|
||||
data,
|
||||
now
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -127,12 +131,14 @@ export function resizeSession(uid, cols, rows) {
|
|||
const {termGroups} = getState();
|
||||
const group = findBySession(termGroups, uid);
|
||||
const isStandaloneTerm = !group.parentUid && !group.children.length;
|
||||
const now = Date.now();
|
||||
dispatch({
|
||||
type: SESSION_RESIZE,
|
||||
uid,
|
||||
cols,
|
||||
rows,
|
||||
isStandaloneTerm,
|
||||
now,
|
||||
effect() {
|
||||
rpc.emit('resize', {uid, cols, rows});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue