How to use the immer.original function in immer

To help you get started, we’ve selected a few 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 kalmhq / kalm / frontend / src / reducers / component.ts View on Github external
const putComponentIntoState = (
  state: State,
  applicationName: string,
  component: ApplicationComponentDetails,
  isCreate: boolean,
): State => {
  let components = state.components[applicationName];
  let componentIndex = -1;
  if (!components) {
    state.components[applicationName] = [];
  } else {
    componentIndex = original(components)!.findIndex((c) => c.name === component.name);
  }
  if (componentIndex < 0) {
    if (isCreate) {
      state.components[applicationName].push(component);
    }
  } else {
    state.components[applicationName][componentIndex] = component;
  }

  return state;
};
github kalmhq / kalm / frontend / src / reducers / sso.ts View on Github external
};

        switch (action.payload.action) {
          case RESOURCE_ACTION_UPDATE:
          case RESOURCE_ACTION_ADD: {
            const index = findIndex(original(state.protectedEndpoints)!);
            if (index < 0) {
              state.protectedEndpoints.unshift(endpoint);
            } else {
              state.protectedEndpoints[index] = endpoint;
            }

            return;
          }
          case RESOURCE_ACTION_DELETE: {
            const index = findIndex(original(state.protectedEndpoints)!);
            if (index >= 0) {
              state.protectedEndpoints.splice(index, 1);
            }
            return;
          }
        }
      } else {
        return;
      }
      return;
    }
  }

  return;
}, initialState);

immer

Create your next immutable state by mutating the current one

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis