How to use ts-action-immer - 6 common examples

To help you get started, we’ve selected a few ts-action-immer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github senstate / platform / apps / senstate-dashboard / src / app / state / hub.reducer.ts View on Github external
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 = {};
github senstate / platform / apps / senstate-dashboard / src / app / state / hub.reducer.ts View on Github external
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;
github senstate / platform / apps / senstate-dashboard / src / app / state / hub.reducer.ts View on Github external
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);
}
github senstate / platform / apps / senstate-dashboard / src / app / state / hub.reducer.ts View on Github external
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) {
github senstate / platform / apps / senstate-dashboard / src / app / state / hub.reducer.ts View on Github external
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);
}
github senstate / platform / apps / senstate-dashboard / src / app / state / hub.reducer.ts View on Github external
}

    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;

ts-action-immer

Immer-based reducer creators for Redux

MIT
Latest version published 4 years ago

Package Health Score

48 / 100
Full package analysis

Popular ts-action-immer functions