{"id":13735604,"url":"https://github.com/plrenaudin/svelte-storez","last_synced_at":"2025-04-22T11:33:31.959Z","repository":{"id":42805093,"uuid":"242417081","full_name":"plrenaudin/svelte-storez","owner":"plrenaudin","description":"Svelte writable store with some extras","archived":false,"fork":false,"pushed_at":"2023-10-28T21:34:27.000Z","size":527,"stargazers_count":27,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T00:24:00.829Z","etag":null,"topics":["history","localstorage","store","svelte","sveltejs"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/storez-demo-c11v9","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plrenaudin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-22T21:54:46.000Z","updated_at":"2024-08-03T03:05:08.461Z","dependencies_parsed_at":"2024-08-03T03:15:09.588Z","dependency_job_id":null,"html_url":"https://github.com/plrenaudin/svelte-storez","commit_stats":{"total_commits":62,"total_committers":3,"mean_commits":"20.666666666666668","dds":"0.11290322580645162","last_synced_commit":"a98e8cad2b2c6c9d036f230fb9a76bf7dcd389eb"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plrenaudin%2Fsvelte-storez","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plrenaudin%2Fsvelte-storez/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plrenaudin%2Fsvelte-storez/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plrenaudin%2Fsvelte-storez/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plrenaudin","download_url":"https://codeload.github.com/plrenaudin/svelte-storez/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250232444,"owners_count":21396643,"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":["history","localstorage","store","svelte","sveltejs"],"created_at":"2024-08-03T03:01:08.745Z","updated_at":"2025-04-22T11:33:31.900Z","avatar_url":"https://github.com/plrenaudin.png","language":"JavaScript","funding_links":[],"categories":["Undo"],"sub_categories":[],"readme":"# Storez\n\n\u003cimg src=\"https://img.shields.io/bundlephobia/minzip/storez\" /\u003e\n\n## Svelte writable store with extra feature\n\n- **Fully compatible** with svelte writable store\n- Subscriber function receives the new **and the old value**\n- Read and persist value to localstorage\n- Keep previous values in **history** (**undo** store mutation with `undo()`)\n- Write operation **debouncing**\n- Get current value without having to subscribe or use `svelte/store` **get** method\n\n## Installation\n\n```\nnpm install storez\n```\n\n## Usage example\n\nCheck out the [Demo](https://codesandbox.io/s/storez-demo-c11v9)\n\n### Basic example\n\n```js\nimport storez from \"storez\";\n\nconst myStore = storez(\"my value\");\n\nconst dispose = myStore.subscribe((newVal, oldVal) =\u003e {\n  console.log(`'${oldVal}' has been changed to '${mewVal}'`);\n});\n\nmyStore.set(\"changed value\"); // console output: 'my value' has been changed to 'changed value'\n```\n\n### With localStorage\n\n```js\nimport storez from \"storez\";\n\nconst myStore = storez(\"my value\", { localstorage: { key: \"myPersistedStore\" } });\n\nconst dispose = myStore.subscribe(() =\u003e {...});\n\nmyStore.set(\"changed value\");\n\nlocalstorage.getItem(\"myPersistedStore\") // === \"my value\"\n\ndispose(); // persist in localStorage\n\nlocalstorage.getItem(\"myPersistedStore\") // === \"changed value\"\n```\n\n### With history\n\n```js\nimport storez from \"storez\";\n\nexport const store = storez(\"my value\", { history: { size: 1000 } });\n\nstore.set(\"changed value\");\n\nstore.set(\"another value\");\n\n// Undo last mutation:\nstore.z.undo();\n```\n\nIn the Svelte file:\n\n```html\n\u003cscript\u003e\n  import { store } from \"./store\";\n  const history = store.z.history; // is a Svelte derived store containing an array of all the previous values\n  // e.g. [\"my value\", \"changed value\"]\n\u003c/script\u003e\n\n\u003cinput type=\"text\" bind:value=\"{$store}\" /\u003e\n\u003cp\u003eValue: {$store}\u003c/p\u003e\n\n\u003cstrong\u003eHistory\u003c/strong\u003e\n\u003cul\u003e\n  {#each $history as item}\n  \u003cli\u003e{item}\u003c/li\u003e\n  {/each}\n\u003c/ul\u003e\n\u003cbutton on:click=\"{store.z.undo}\"\u003eUndo\u003c/button\u003e\n```\n\n## API\n\n### Constructor\n\n```js\n// Svelte compatible store API\nstorez(val);\nstorez(val, start);\n\n// Same with Storez options\nstorez(val, options);\nstorez(val, start, options);\n```\n\n### Storez instance\n\n```js\nconst instance = storez(\"initial\", ...);\ninstance.set(\"newValue\");\ninstance.set(\"wrongValue\");\n\ninstance.z.get() // returns the current value of the store (e.g. \"wrongValue\") This value is not reactive\n\n// If History module enabled:\ninstance.z.history; // History module: Svelte readable store containing the state history\ninstance.z.undo(); // History module: undo last mutation\n// Here: instance === newValue\ninstance.z.redo();\n// Here: instance === wrongValue\n\n\n```\n\n## Options\n\n| Module       | Options  | Type   | Details                                                  |\n| ------------ | -------- | ------ | -------------------------------------------------------- |\n| (default)    | debounce | Number | Timeout between each insert in the store                 |\n| localstorage | key      | String | Key under which the local storage will be saved          |\n| history      | size     | Number | Overall size of the array of element kept in the history |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplrenaudin%2Fsvelte-storez","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplrenaudin%2Fsvelte-storez","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplrenaudin%2Fsvelte-storez/lists"}