Socket
Book a DemoInstallSign in
Socket

history-adapter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

history-adapter

A "history adapter" for managing undoable (and redoable) state changes.

latest
Source
npmnpm
Version
2.1.1
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

History Adapter

logo

A "history adapter" for managing undoable (and redoable) state changes with immer, which pairs well with state management solutions like Redux and Zustand.

Includes generic methods along with Redux-specific helpers.

import { createHistoryAdapter } from "history-adapter/redux";
import { createSlice } from "@reduxjs/toolkit";

interface CounterState {
  value: number;
}

const counterAdapter = createHistoryAdapter<CounterState>({ limit: 10 });

const counterSlice = createSlice({
  name: "counter",
  initialState: { value: 0 },
  reducers: {
    undo: counterAdapter.undo,
    redo: counterAdapter.redo,
    increment: counterAdapter.undoableReducer((state) => {
      state.value += 1;
    }),
  },
});

See website for more information.

Keywords

history

FAQs

Package last updated on 17 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts