Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
eventsByApp: {},
watcherToApp: {},
eventsCounter: {},
logsByApp: {},
errorsByApp: {},
// from cli
meta: {
apps: {}
}
};
const topicReducer = createReducer(
HubReducerInitState,
on(HubActions.GOT_META, (state, action) => {
// remove events of a removed app
const currentAppIdList = Object.keys(state.meta.apps);
const newAppIdList = Object.keys(action.payload.apps);
currentAppIdList.map(app => {
if (!newAppIdList.includes(app)) {
delete state.eventsByApp[app];
}
});
// set meta
state.meta = action.payload;
const watcherToApp: WatcherToApp = {};
state.meta = action.payload;
const watcherToApp: WatcherToApp = {};
newAppIdList.map(app => {
Object.keys(state.meta.apps[app].watchers)
.map(watchId => {
watcherToApp[watchId] = app;
});
});
// update the watcher to app map
state.watcherToApp = watcherToApp;
}),
on(HubActions.RECEIVED_DATA, (state, {payload}) => {
const {watchId, data} = payload;
if (!state.watcherToApp[watchId]) {
return;
}
const appId = state.watcherToApp[watchId];
if (state.watchersPaused[`${appId}_${watchId}`]) {
return;
}
const eventsByApp = state.eventsByApp[appId] = state.eventsByApp[appId] || {};
eventsByApp[watchId] = data;
const counterElement = state.eventsCounter[watchId] || 0;
state.eventsCounter[watchId] = counterElement + 1;
on(HubActions.LOG_DATA, (state, {payload}) => {
const logsAr = state.logsByApp[payload.appId] = state.logsByApp[payload.appId] || [];
logsAr.push(payload);
}),
on(HubActions.ERROR_DATA, (state, {payload}) => {
const errorAr = state.errorsByApp[payload.appId] = state.errorsByApp[payload.appId] || [];
errorAr.push(payload);
}),
on(HubActions.STATUS_CHANGED, (state, action) => {
state.socketStatus = action.payload;
}),
on(DashboardActions.TOGGLE_PAUSE, (state, action) => {
const paused = state.watchersPaused[action.payload] || false;
state.watchersPaused[action.payload] = !paused;
console.info(state.watchersPaused, paused);
})
);
export function hubReducer (state: HubState | undefined, action: Action) {
return topicReducer(state, action);
}
return;
}
const eventsByApp = state.eventsByApp[appId] = state.eventsByApp[appId] || {};
eventsByApp[watchId] = data;
const counterElement = state.eventsCounter[watchId] || 0;
state.eventsCounter[watchId] = counterElement + 1;
}),
on(HubActions.LOG_DATA, (state, {payload}) => {
const logsAr = state.logsByApp[payload.appId] = state.logsByApp[payload.appId] || [];
logsAr.push(payload);
}),
on(HubActions.ERROR_DATA, (state, {payload}) => {
const errorAr = state.errorsByApp[payload.appId] = state.errorsByApp[payload.appId] || [];
errorAr.push(payload);
}),
on(HubActions.STATUS_CHANGED, (state, action) => {
state.socketStatus = action.payload;
}),
on(DashboardActions.TOGGLE_PAUSE, (state, action) => {
const paused = state.watchersPaused[action.payload] || false;
state.watchersPaused[action.payload] = !paused;
console.info(state.watchersPaused, paused);
})
);
export function hubReducer (state: HubState | undefined, action: Action) {
const counterElement = state.eventsCounter[watchId] || 0;
state.eventsCounter[watchId] = counterElement + 1;
}),
on(HubActions.LOG_DATA, (state, {payload}) => {
const logsAr = state.logsByApp[payload.appId] = state.logsByApp[payload.appId] || [];
logsAr.push(payload);
}),
on(HubActions.ERROR_DATA, (state, {payload}) => {
const errorAr = state.errorsByApp[payload.appId] = state.errorsByApp[payload.appId] || [];
errorAr.push(payload);
}),
on(HubActions.STATUS_CHANGED, (state, action) => {
state.socketStatus = action.payload;
}),
on(DashboardActions.TOGGLE_PAUSE, (state, action) => {
const paused = state.watchersPaused[action.payload] || false;
state.watchersPaused[action.payload] = !paused;
console.info(state.watchersPaused, paused);
})
);
export function hubReducer (state: HubState | undefined, action: Action) {
return topicReducer(state, action);
}
}
const appId = state.watcherToApp[watchId];
if (state.watchersPaused[`${appId}_${watchId}`]) {
return;
}
const eventsByApp = state.eventsByApp[appId] = state.eventsByApp[appId] || {};
eventsByApp[watchId] = data;
const counterElement = state.eventsCounter[watchId] || 0;
state.eventsCounter[watchId] = counterElement + 1;
}),
on(HubActions.LOG_DATA, (state, {payload}) => {
const logsAr = state.logsByApp[payload.appId] = state.logsByApp[payload.appId] || [];
logsAr.push(payload);
}),
on(HubActions.ERROR_DATA, (state, {payload}) => {
const errorAr = state.errorsByApp[payload.appId] = state.errorsByApp[payload.appId] || [];
errorAr.push(payload);
}),
on(HubActions.STATUS_CHANGED, (state, action) => {
state.socketStatus = action.payload;
}),
on(DashboardActions.TOGGLE_PAUSE, (state, action) => {
const paused = state.watchersPaused[action.payload] || false;
state.watchersPaused[action.payload] = !paused;