{"id":15038655,"url":"https://github.com/voluntadpear/reswiftundo","last_synced_at":"2025-07-10T17:32:48.437Z","repository":{"id":62452571,"uuid":"87655279","full_name":"voluntadpear/ReSwiftUndo","owner":"voluntadpear","description":"Swift implementation of redux-undo for ReSwift for use with ReSwift","archived":false,"fork":false,"pushed_at":"2017-05-17T18:27:31.000Z","size":40,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T08:02:46.330Z","etag":null,"topics":["cocoapods","redux","redux-undo","reswift","swift","swift-3","swift3","undo-redo"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/voluntadpear.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":"2017-04-08T18:29:09.000Z","updated_at":"2022-04-11T10:24:18.000Z","dependencies_parsed_at":"2022-11-01T23:46:30.216Z","dependency_job_id":null,"html_url":"https://github.com/voluntadpear/ReSwiftUndo","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/voluntadpear/ReSwiftUndo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voluntadpear%2FReSwiftUndo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voluntadpear%2FReSwiftUndo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voluntadpear%2FReSwiftUndo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voluntadpear%2FReSwiftUndo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voluntadpear","download_url":"https://codeload.github.com/voluntadpear/ReSwiftUndo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voluntadpear%2FReSwiftUndo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264619481,"owners_count":23638461,"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":["cocoapods","redux","redux-undo","reswift","swift","swift-3","swift3","undo-redo"],"created_at":"2024-09-24T20:39:31.240Z","updated_at":"2025-07-10T17:32:48.418Z","avatar_url":"https://github.com/voluntadpear.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/voluntadpear/ReSwiftUndo.svg?branch=master\u0026style=flat-square)](https://travis-ci.org/voluntadpear/ReSwiftUndo)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) \n[![](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/voluntadpear/ReSwiftUndo/blob/master/LICENSE)\n\n# ReSwiftUndo\nSwift implementation of [redux-undo](https://github.com/omnidan/redux-undo) for Swift to use with [ReSwift](https://github.com/ReSwift/ReSwift) 4.0\n\n***Work in progress***\n\n## Use\n\nSuppose the state of your app is like this:\n```swift\nstruct State: StateType, Equatable {\n    var counter: Int = 0\n\n    static func ==(lhr: State, rhr: State) -\u003e Bool {\n        return lhr.counter == rhr.counter\n    }\n}\n```\n\n**Notice:** it's important that your State conforms to the Equatable protocol.\n\nAnd your reducer looks like this:\n```swift\nfunc reducer(action: Action, state: State?) -\u003e State {\n    var state = state ?? initialState()\n    switch action {\n    case _ as Increase:\n        state.counter = state.counter + 1\n    case _ as Decrease:\n        state.counter = state.counter - 1\n    default:\n        break\n    }\n    return state\n}\n```\nWith ReSwiftUndo you can trigger actions that lets you go back to your previous state and back to the recent one.\n\nWrapping your state with `undoable` makes the state look like this:\n\n```swift\npublic struct UndoableState\u003cT\u003e: StateType {\n    public var past: [T]\n    public var present: T\n    public var future: [T]\n}\n```\nNow you can get the current state like this: `state.present`\n\n```swift\nlet appReducer = undoable(reducer: reducer)\n\nvar store = Store\u003cUndoableState\u003cState\u003e\u003e(reducer: appReducer, state: nil)\n```\n\nIf you only need a substate of your app to be undoable you can do something like this:\n```swift\nfunc appReducer(action: Action, state: State?) -\u003e State {\n    let folderUndoableReducer = undoable(reducer: foldersReducer, filter: filterCondition)\n    return State(\n            authenticationState: authenticationReducer(action: action, state: state?.authenticationState),\n            commonState: commonReducer(action: action, state: state?.commonState),\n            foldersState: folderUndoableReducer(action, state?.foldersState)\n        )\n}\n```\n\nYou can now trigger the `Undo` and `Redo` actions and do things like these:\n\n```swift\nprint(store.state.present.counter) // 0\nstore.dispatch(Increase())\nprint(store.state.present.counter) // 1\nprint(store.state.past[0].counter) // 0\nstore.dispatch(Undo())\nprint(store.state.present.counter) // 0\nprint(store.state.future[0].counter) // 1\nstore.dispatch(Redo())\nprint(store.state.present.counter) // 1\n```\n\n### Filtering actions\nNotice that only actions resulting in a new state are recorded. But if you want to discard some actions in the undo/redo history, or to only record history if a certain part of the state is changed you can\nadd a `filter` function to `undoable`. \n\nIf you want to create your own filter, pass in a function or closure with the parameters of type \n`(Action, T, UndoableState\u003cT\u003e)` where you receive the action dispatched, the new currentState and the previous history. For example:\n\n```swift\nlet filterCondition: UndoableFilter\u003cFoldersState\u003e = { (_, new, previous) in\n            let previousPresent = previous.present\n            let sameFolder = previousPresent.folder?.itemId == new.folder?.itemId\n            return !sameFolder\n        }\n        \nlet folderUndoableReducer: (Action, UndoableState\u003cFoldersState\u003e?) -\u003e UndoableState\u003cFoldersState\u003e = \nundoable(reducer: foldersReducer, filter: filterCondition)\n```\n## Install\n\n### CocoaPods\n\nAdd to your `Podfile`:\n```\npod 'ReSwiftUndo'\n```\n\nRun `pod install`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoluntadpear%2Freswiftundo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoluntadpear%2Freswiftundo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoluntadpear%2Freswiftundo/lists"}