{"id":13735786,"url":"https://github.com/endenwer/svelte-restate","last_synced_at":"2025-04-12T17:35:00.704Z","repository":{"id":57375332,"uuid":"353333229","full_name":"endenwer/svelte-restate","owner":"endenwer","description":"Immutable store for Svelte with full Typescript support and Redux Devtools integration.","archived":false,"fork":false,"pushed_at":"2022-02-15T16:35:02.000Z","size":236,"stargazers_count":21,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T12:01:35.647Z","etag":null,"topics":["redux-devtools","state-management","store","svelte"],"latest_commit_sha":null,"homepage":"https://endenwer.github.io/svelte-restate/","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/endenwer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-03-31T11:31:07.000Z","updated_at":"2022-12-04T07:47:18.000Z","dependencies_parsed_at":"2022-09-05T13:21:11.656Z","dependency_job_id":null,"html_url":"https://github.com/endenwer/svelte-restate","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endenwer%2Fsvelte-restate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endenwer%2Fsvelte-restate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endenwer%2Fsvelte-restate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endenwer%2Fsvelte-restate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/endenwer","download_url":"https://codeload.github.com/endenwer/svelte-restate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248605906,"owners_count":21132262,"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":["redux-devtools","state-management","store","svelte"],"created_at":"2024-08-03T03:01:11.174Z","updated_at":"2025-04-12T17:35:00.682Z","avatar_url":"https://github.com/endenwer.png","language":"TypeScript","funding_links":[],"categories":["(Im)mutability"],"sub_categories":[],"readme":"## Svelte Restate\n\nImmutable store for Svelte with full Typescript support and Redux Devtools integration. It is highly inspired by [re-frame](https://github.com/day8/re-frame) subscriptions(read more about signal graph and subscription layers [here](https://day8.github.io/re-frame/subscriptions/)). [Immer](https://immerjs.github.io/immer/) is used to work with immutable state.\n\n\u003ca id=install\u003e\u003c/a\u003e\n## Install\n\n```sh\nnpm i svelte-restate --save\n```\n\n\u003ca id=usage\u003e\u003c/a\u003e\n## Usage [[Demo]](https://svelte-restate-example.netlify.app/)\n\nCreate store with initial state.\n```ts\nimport { createStore } from 'svelte-restate'\n\nexport interface State {\n  isLoading\n  todos: {\n    id: number\n    completed: boolean\n    description: string\n  }[]\n}\n\nconst initState: State = {\n  isLoading: true,\n  todos: []\n}\n\nexport default createStore(initState)\n```\n\nCreate subscriptions. See more examples in documentation for [`RegRootsub`](/docs/API.md#reg-root-sub) and [`RegSub`](/docs/API.md#reg-sub).\n```ts\nimport store from './store'\n\n// register root subs\nconst isLoading = store.regRootSub(\n  'isLoading',\n  ($root) =\u003e $root.count\n)\n\nconst todos = store.regRootSub(\n  'todos',\n  ($root) =\u003e $root.todos\n)\n\n// use root subs to register derived subs\nconst completedTodos = store.regSub(\n  'completedTodos',\n  () =\u003e todos()\n  ($todos) =\u003e $todos.filter(todo =\u003e todo.completed)\n)\n\n// register sub with arguments\nconst todo = store.regSub(\n  'todo',\n  () =\u003e todos()\n  ($todos, [id]: [number]) =\u003e $todos.find(todo =\u003e todo.id === id)\n)\n\nexport default { count }\n```\n\nCreate mutations. See more examples in documentation for [`RegMut`](/docs/API.md#reg-mut).\n```ts\nimport store from './store'\n\nconst setLoading = store.regMut\u003cboolean\u003e(\n  'setLoading',\n  (draft, value) =\u003e draft.isLoading = value\n)\n\nconst insertTodos = store.RegMut\u003cTodo[]\u003e(\n  'insertTodos',\n  (draft, todos) =\u003e draft.todos = todos\n)\n\nexport default { setLoading, insertTodos }\n```\n\nUse in svelte component.\n```html\n\u003cscript\u003e\n  import muts from './muts'\n  import subs from './subs'\n  import store from './store'\n  import { onMount } 'svelete'\n  import { fetchTodos } './api'\n\n  // subscription without arguments.\n  // To get the value use '$isLoading'\n  const isLoading = subs.isLoading()\n\n  // subscription with arguments\n  export let id: number\n  $: todo = subs.todo(id)\n\n  // use mutations\n  onMount(async () =\u003e {\n   muts.setLoading(true)\n   const todos = await fetchTodos()\n\n   // call multiple mutations within transaction\n   store.transaction(tx =\u003e [\n     muts.setIsLoading(false, tx),\n     muts.insertTodos(todos, tx)\n   ])\n  })\n\u003c/script\u003e\n\n{# if $isLoading}\n  \u003cdiv\u003eLoading...\u003c/div\u003e\n{:else}\n  \u003cdiv\u003e{$todo.description}\u003c/div\u003e\n{/if}\n```\n\nConnect to Redux devtools. You can see main state, state of all active subscriptions and dispatch mutations directly from the devtools. Time travel also works. See documentation for [`connectToDevtools`](/docs/API.md#connect-to-devtools).\n```ts\nimport muts from './muts'\nimport store from './store'\n\nconnectToDevTools(store, muts)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendenwer%2Fsvelte-restate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendenwer%2Fsvelte-restate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendenwer%2Fsvelte-restate/lists"}