{"id":25229041,"url":"https://github.com/andres-kovalev/undoable-reducer","last_synced_at":"2025-04-05T14:12:39.660Z","repository":{"id":57385959,"uuid":"199219904","full_name":"andres-kovalev/undoable-reducer","owner":"andres-kovalev","description":"Simple utility to make reducers undoable","archived":false,"fork":false,"pushed_at":"2020-03-25T17:20:09.000Z","size":13,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T01:50:31.080Z","etag":null,"topics":["redo-actions","reducer","undo","undoable"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andres-kovalev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-27T22:45:27.000Z","updated_at":"2020-03-25T17:16:02.000Z","dependencies_parsed_at":"2022-09-14T21:04:08.106Z","dependency_job_id":null,"html_url":"https://github.com/andres-kovalev/undoable-reducer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fundoable-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fundoable-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fundoable-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andres-kovalev%2Fundoable-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andres-kovalev","download_url":"https://codeload.github.com/andres-kovalev/undoable-reducer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345844,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["redo-actions","reducer","undo","undoable"],"created_at":"2025-02-11T10:46:58.789Z","updated_at":"2025-04-05T14:12:39.639Z","avatar_url":"https://github.com/andres-kovalev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![ci](https://img.shields.io/circleci/build/github/andres-kovalev/undoable-reducer.svg?style=flat-square\u0026logo=circleci)](https://circleci.com/gh/andres-kovalev/undoable-reducer)\n[![codecov](https://img.shields.io/codecov/c/github/andres-kovalev/undoable-reducer.svg?style=flat-square\u0026logo=codecov\u0026token=1280f2cf41a24522add9857967be2a73)](https://codecov.io/gh/andres-kovalev/undoable-reducer)\n[![downloads](https://img.shields.io/npm/dm/undoable-reducer.svg?style=flat-square\u0026logo=data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJDYXBhXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Igp3aWR0aD0iNDAwcHgiIGhlaWdodD0iNDAwcHgiIHhtbDpzcGFjZT0icHJlc2VydmUiCj48ZyBmaWxsPSJ3aGl0ZSI+PHBhdGggZD0iTTM3OSwxODAuNWgtMTAydi0xMDBoLTE1M3YxMDBoLTEwMmwxNzguNSwxNzguNWwxNzguNSwtMTc4LDUiLz48L2c+PC9zdmc+Cg==)](https://www.npmjs.com/package/undoable-reducer)\n[![node](https://img.shields.io/node/v/undoable-reducer.svg?style=flat-square\u0026logo=node.js\u0026color=007ec6)](https://nodejs.org/)\n[![npm](https://img.shields.io/npm/v/undoable-reducer.svg?style=flat-square\u0026logo=npm)](https://www.npmjs.com/package/undoable-reducer)\n[![MIT](https://img.shields.io/npm/l/undoable-reducer.svg?color=007ec6\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAA5ElEQVR4AY3SJWyDcRQE8G+MsnIg63XNmMm2ZuB9xjyv5tWYfAZ2TD6tGW9qzHCX3H9bX4rJz7y7K3t8NK20OT7ogHnYl3ndfK5nRwFYgxf4Nl6UBVzfjcoholIiEXbdsBS2TCERdks5HIaPVIfqDnN4HCO8gUm5iZEfc/gYI+gBT3pi5I8M3szxE0LgSYg303ljcGqOtAHFshEjP+VwOkbwCvXyGiOf5rASrkwQhhIJm4zdKg4zYBDe/z8j72Te0bu6GRxSIUzAHXxBF3jSpdudOoX2/5oDQVgEP3ji1y3Ijhv9ABp7euvVsybrAAAAAElFTkSuQmCC\u0026style=flat-square)](https://github.com/andres-kovalev/undoable-reducer/blob/master/LICENSE)\n[![npm bundle size](https://img.shields.io/bundlephobia/min/undoable-reducer.svg?style=flat-square\u0026logo=data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJDYXBhXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Igp3aWR0aD0iNDAwcHgiIGhlaWdodD0iNDAwcHgiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxnIGZpbGw9IndoaXRlIj48cGF0aCBkPSJNNzUsMzBoMTc1bDEwMCwxMDB2MjQwaC0yNzV2LTI0MCIvPjwvZz48ZyBmaWxsPSIjREREIj48cGF0aCBkPSJNMjUwLDMwbDEwMCwxMDBoLTEwMHYtMTAwIi8+PC9nPjwvc3ZnPgo=)](https://www.npmjs.com/package/undoable-reducer)\n\n# undoable-reducer\n\nSimple utility to make reducers undoable.\n\n# Description\n\n`undoable-reducer` provides simple utility to make any reducer undoable.\n\nHere is a small [demo](https://codesandbox.io/s/undoable-reducer-playground-xgqtn).\n\n# Installation\n\nAs any other npm package `undoable-reducer` can be added to your project by following command:\n\n```bash\nnpm i -S undoable-reducer\n```\n\n# API\n\n## makeUndoable(reducer, options)\n\nTo make any reducer undoable just pass it to `makeUndoable()` function as 1st argument:\n\n```js\nimport makeUndoable from 'undoable-reducer';\n\nconst reducer = (state, action) =\u003e {\n    ...\n};\n\nexport default makeUndoable(reducer);\n```\n\nTo use undo/redo functionality, `undoable-reducer` exports action types for undo and redo actions:\n\n```js\nimport { TYPES } from 'undoable-reducer';\n\nconst Component = ({ dispatch }) =\u003e {\n    ...\n    dispatch({ type: TYPES.undo });\n};\n```\n\n`undoable-reducer` exports action creators as well:\n\n```js\nimport { ACTIONS } from 'undoable-reducer';\n\nconst Component = ({ dispatch }) =\u003e {\n    ...\n    dispatch(ACTIONS.undo());\n};\n```\n\nTo use undo/redo functionality across several reducers `makeUndoable()` can be applied to combined reducer...\n\n```js\nimport makeUndoable from 'undoable-reducer';\nimport combineReducers from 'redux';\nimport theme from './theme';\nimport locale from './locale';\nimport editor from './locale';\n\n// to add undo/redo functionality to whole state\nexport default makeUndoable(combineReducers({\n    theme, locale, editor\n}));\n```\n\nor any specific reducer:\n\n```js\n...\n\n// to add undo/redo functionality editor state only\nexport default combineReducers({\n    theme, locale,\n    editor: makeUndoable(editor)\n});\n```\n\n`makeUndoable()` function can be configured using `options` parameter.\n\nIn some cases we may want to use custom undo/redo actions. To do so we just need to pass undo and redo action types during `makeUndoable()` call:\n\n```js\nimport { CUSTOM_UNDO as undo, CUSTOM_REDO as redo } from '../actions/editor';\n\nexport default makeUndoable(editorReducer, {\n    types: { undo, redo }\n})\n```\n\nBy doing so we can group several states under the same undo/redo history.\n\nThere is another option `length` to set maximum history length for undoable reducer (which is 10 by default):\n\n```js\n// use will be able to undo (and then redo) up to 20 times\nexport default makeUndoable(reducer, { length: 20 });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandres-kovalev%2Fundoable-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandres-kovalev%2Fundoable-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandres-kovalev%2Fundoable-reducer/lists"}