{"id":13735616,"url":"https://github.com/macfja/svelte-undoable","last_synced_at":"2025-03-19T12:31:09.258Z","repository":{"id":57127270,"uuid":"294919704","full_name":"MacFJA/svelte-undoable","owner":"MacFJA","description":"Memento design pattern in Svelte","archived":false,"fork":false,"pushed_at":"2021-02-20T18:48:01.000Z","size":112,"stargazers_count":45,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T07:11:18.378Z","etag":null,"topics":["memento","stores","svelte","svelte-component","sveltejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/MacFJA.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-12T10:19:41.000Z","updated_at":"2024-08-22T13:02:37.000Z","dependencies_parsed_at":"2022-08-31T17:20:20.419Z","dependency_job_id":null,"html_url":"https://github.com/MacFJA/svelte-undoable","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/MacFJA%2Fsvelte-undoable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacFJA%2Fsvelte-undoable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacFJA%2Fsvelte-undoable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacFJA%2Fsvelte-undoable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MacFJA","download_url":"https://codeload.github.com/MacFJA/svelte-undoable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244426601,"owners_count":20450995,"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":["memento","stores","svelte","svelte-component","sveltejs"],"created_at":"2024-08-03T03:01:08.874Z","updated_at":"2025-03-19T12:31:07.452Z","avatar_url":"https://github.com/MacFJA.png","language":"TypeScript","funding_links":[],"categories":["Undo"],"sub_categories":[],"readme":"# Svelte Undoable store\n\nMemento design pattern in Svelte\n\n## Installation\n\n```\nnpm install @macfja/svelte-undoable\n```\n\n## Usage\n\n```javascript\nimport { undoable } from \"@macfja/svelte-undoable\"\n\nlet name = undoable(\"John\")\n\n$name = \"Jeanne\"\n$name = \"Doe\"\n\nname.undo()\n// Now the value of $name is \"Jeanne\"\n\nname.undo()\n// Now $name is \"John\"\n\nname.redo()\n// Now $name is \"Jeanne\" again\n```\n\n## Example\n\n```html\n\u003cscript\u003e\nimport { undoable, undo, redo, reset, canUndo, canRedo } from \"@macfja/svelte-undoable\"\nimport { derived } from \"svelte/store\"\n\nlet name = undoable(\"John\")\nlet canUndoName = derived([name], () =\u003e canUndo(name))\nlet canRedoName = derived([name], () =\u003e canRedo(name))\n\nlet counter = undoable(0, 10, value =\u003e value%2 === 0)\nlet canUndoCounter = derived([counter], () =\u003e counter.canUndo())\nlet canRedoCounter = derived([counter], () =\u003e counter.canRedo())\n\u003c/script\u003e\n\n\u003ch1\u003eHello {$name}\u003c/h1\u003e\n\n\u003cinput bind:value={$name} /\u003e\n\u003cbutton disabled={!$canUndoName} on:click={() =\u003e undo(name)}\u003eUndo\u003c/button\u003e\n\u003cbutton disabled={!$canRedoName} on:click={() =\u003e redo(name)}\u003eRedo\u003c/button\u003e\n\u003cbutton disabled={!$canUndoName} on:click={() =\u003e reset(name)}\u003eReset\u003c/button\u003e\n\n\u003chr /\u003e\nOnly even number as saved in the store history. The maximum number of remembered value is 10.\n(If you go to \u003ccode\u003e20\u003c/code\u003e, you can only go back to \u003ccode\u003e2\u003c/code\u003e)\n\n\u003cbutton on:click={() =\u003e $counter++}\u003e\n  Clicked {$counter} {$counter === 1 ? 'time' : 'times'}\n\u003c/button\u003e\n\u003cbutton disabled={!$canUndoCounter} on:click={() =\u003e undo(counter)}\u003eUndo\u003c/button\u003e\n\u003cbutton disabled={!$canRedoCounter} on:click={() =\u003e redo(counter)}\u003eRedo\u003c/button\u003e\n```\n([REPL](https://svelte.dev/repl/9412d77adca64a668055027e84619090?version=3.25.0))\n\n## Contributing\n\nContributions are welcome. Please open up an issue or create PR if you would like to help out.\n\nRead more in the [Contributing file](CONTRIBUTING.md)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacfja%2Fsvelte-undoable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacfja%2Fsvelte-undoable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacfja%2Fsvelte-undoable/lists"}