{"id":27129265,"url":"https://github.com/amoreaulemay/fresh-store","last_synced_at":"2025-08-11T13:09:53.681Z","repository":{"id":52238182,"uuid":"520585111","full_name":"amoreaulemay/fresh-store","owner":"amoreaulemay","description":"Simple store for Deno Fresh, to pass state between islands","archived":false,"fork":false,"pushed_at":"2022-08-25T00:39:18.000Z","size":52,"stargazers_count":13,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-14T19:01:56.884Z","etag":null,"topics":["deno","fresh","state-management","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/fresh_store@v1.0.1/mod.ts","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/amoreaulemay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-02T17:12:25.000Z","updated_at":"2025-05-31T17:17:57.000Z","dependencies_parsed_at":"2022-08-13T01:22:12.003Z","dependency_job_id":null,"html_url":"https://github.com/amoreaulemay/fresh-store","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/amoreaulemay/fresh-store","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoreaulemay%2Ffresh-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoreaulemay%2Ffresh-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoreaulemay%2Ffresh-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoreaulemay%2Ffresh-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amoreaulemay","download_url":"https://codeload.github.com/amoreaulemay/fresh-store/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoreaulemay%2Ffresh-store/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269893003,"owners_count":24492026,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","fresh","state-management","typescript"],"created_at":"2025-04-07T19:31:28.339Z","updated_at":"2025-08-11T13:09:53.627Z","avatar_url":"https://github.com/amoreaulemay.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fresh Store\n\n![Build Passing](https://github.com/amoreaulemay/fresh-store/actions/workflows/deno.yml/badge.svg) [![](https://img.shields.io/codecov/c/gh/amoreaulemay/fresh-store?style=flat-square)](https://codecov.io/gh/amoreaulemay/fresh-store) ![CodeQL](https://github.com/amoreaulemay/fresh-store/workflows/CodeQL/badge.svg)\n\nA minimal store for Fresh, to allow communication between islands. It attach stores to the `window` component. It uses \"pointers\" or \"keys\" to associate stores. A pointer can either be provided, or auto-generated.\n\n## Usage\n\nCreating a store.\n\n```typescript\nconst ptr = useStore(\"Initial Value\", { onChange: (state) =\u003e console.log(state) });\n\nconsole.log(Stores.get\u003cstring\u003e(ptr)?.state);\nStores.get\u003cstring\u003e(ptr)?.set(\"Modified Value\");\n```\n\n```\nOutput:\nInitial Value\nModified Value\n```\n\nCreating a store and providing a pointer.\n\n```typescript\nconst pointer = Store.newPointer();\nuseStore(\n    \"Initial Value\", \n    {\n        pointer: pointer,\n        onChange: (newState) =\u003e console.log(`New value: ${newState}`)\n    },\n);\n\nconsole.log(Stores.get\u003cstring\u003e(ptr)?.state);\nStores.get\u003cstring\u003e(ptr)?.set(\"Modified Value\");\n```\n\n```\nOutput:\nInitial Value\nNew value: Modified Value\n```\n\n## Creating a new Observer\n\n```typescript\nconst storePtr = useStore(\"New Store\");\n\nclass ConcreteObserver implements Observer\u003cT\u003e {\n    public update(subject: Store\u003cT\u003e): void {\n        console.log(\"The store was updated, new state: \", subject.state);\n    }\n}\n\nStores.get(storePtr)?.attach(new ConcreteObserver());\n```\n\n## Example usage in components\n\n```tsx\n// ./islands/componentA.tsx\n\n/** @jsx h */\nimport { h } from \"preact\";\nimport { Stores, useStore, type Pointer } from \"@store\";\n\ninterface CompAProps {\n    storePtr: Pointer;\n}\n\nexport default function ComponentA(props: CompAProps) {\n    useStore(0, { pointer: props.storePtr });\n\n    const increment = () =\u003e \n        Stores\n            .get\u003cnumber\u003e(props.storePtr)\n            ?.set((state) =\u003e state + 1);\n    \n    const decrement = () =\u003e\n       Stores\n            .get\u003cnumber\u003e(props.storePtr)\n            ?.set((state) =\u003e state - 1);\n    \n    return (\n        \u003cdiv\u003e\n            \u003cbutton onClick={decrement}\u003e-1\u003c/button\u003e\n            \u003cbutton onClick={increment}\u003e+1\u003c/button\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\n```tsx\n// ./islands/componentB.tsx\n\n/** @jsx h */\nimport { h } from \"preact\";\nimport { useState } from \"preact/hooks\";\n\nimport { useStore, type Pointer } from \"@store\";\n\ninterface CompBProps {\n    storePtr: Pointer;\n}\n\nexport default function ComponentB(props: CompBProps) {\n    const [counter, setCounter] = useState(0);\n    useStore(counter, {\n        pointer: props.storePtr,\n        onChange: (newState) =\u003e setCounter(newState),\n    });\n\n    return \u003cp\u003eCounter: {counter}\u003c/p\u003e;\n}\n```\n\n```tsx\n// ./routes/index.tsx\n\n/** @jsx h */\nimport { h } from \"preact\";\n\nimport { Store } from \"@store\";\n\nimport ComponentA from \"@islands/componentA.tsx\";\nimport ComponentB from \"@islands/componentB.tsx\";\n\nexport default function Index() {\n    const storePtr = Store.newPointer();\n\n    return (\n        \u003cdiv\u003e\n            \u003cComponentA storePtr={storePtr} /\u003e\n            \u003cComponentB storePtr={storePtr} /\u003e\n        \u003c/div\u003e\n    );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoreaulemay%2Ffresh-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famoreaulemay%2Ffresh-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoreaulemay%2Ffresh-store/lists"}