{"id":21754642,"url":"https://github.com/aegisjsproject/state","last_synced_at":"2025-09-05T17:33:12.440Z","repository":{"id":257825120,"uuid":"872037943","full_name":"AegisJSProject/state","owner":"AegisJSProject","description":"A simple state manager library","archived":false,"fork":false,"pushed_at":"2025-08-29T14:32:16.000Z","size":785,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-29T17:03:14.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@aegisjsproject/state","language":"JavaScript","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/AegisJSProject.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"shgysk8zer0","liberapay":"shgysk8zer0"}},"created_at":"2024-10-13T16:13:44.000Z","updated_at":"2025-08-29T14:32:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"9111159a-23cc-4663-8717-970042deaa43","html_url":"https://github.com/AegisJSProject/state","commit_stats":null,"previous_names":["aegisjsproject/state"],"tags_count":6,"template":false,"template_full_name":"shgysk8zer0/npm-template","purl":"pkg:github/AegisJSProject/state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Fstate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Fstate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Fstate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Fstate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AegisJSProject","download_url":"https://codeload.github.com/AegisJSProject/state/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AegisJSProject%2Fstate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273790554,"owners_count":25168674,"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-09-05T02:00:09.113Z","response_time":402,"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":[],"created_at":"2024-11-26T09:14:34.536Z","updated_at":"2025-09-05T17:33:12.417Z","avatar_url":"https://github.com/AegisJSProject.png","language":"JavaScript","funding_links":["https://github.com/sponsors/shgysk8zer0","https://liberapay.com/shgysk8zer0","https://liberapay.com/shgysk8zer0/donate"],"categories":[],"sub_categories":[],"readme":"# `@aegisjsproject/state`\n\nA lightweight state management library that persists state across navigation within the same session. It leverages `history.state`\nfor easy integration into web applications and synchronizes state across tabs or windows within the same origin using `BroadcastChannel`.\n\n[![CodeQL](https://github.com/AegisJSProject/state/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/AegisJSProject/state/actions/workflows/codeql-analysis.yml)\n![Node CI](https://github.com/AegisJSProject/state/workflows/Node%20CI/badge.svg)\n![Lint Code Base](https://github.com/AegisJSProject/state/workflows/Lint%20Code%20Base/badge.svg)\n\n[![GitHub license](https://img.shields.io/github/license/AegisJSProject/state.svg)](https://github.com/AegisJSProject/state/blob/master/LICENSE)\n[![GitHub last commit](https://img.shields.io/github/last-commit/AegisJSProject/state.svg)](https://github.com/AegisJSProject/state/commits/master)\n[![GitHub release](https://img.shields.io/github/release/AegisJSProject/state?logo=github)](https://github.com/AegisJSProject/state/releases)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/shgysk8zer0?logo=github)](https://github.com/sponsors/shgysk8zer0)\n\n[![npm](https://img.shields.io/npm/v/@aegisjsproject/state)](https://www.npmjs.com/package/@aegisjsproject/state)\n![node-current](https://img.shields.io/node/v/@aegisjsproject/state)\n![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/@aegisjsproject/state)\n[![npm](https://img.shields.io/npm/dw/@aegisjsproject/state?logo=npm)](https://www.npmjs.com/package/@aegisjsproject/state)\n\n[![GitHub followers](https://img.shields.io/github/followers/shgysk8zer0.svg?style=social)](https://github.com/shgysk8zer0)\n![GitHub forks](https://img.shields.io/github/forks/AegisJSProject/state.svg?style=social)\n![GitHub stars](https://img.shields.io/github/stars/AegisJSProject/state.svg?style=social)\n[![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)](https://twitter.com/shgysk8zer0)\n\n[![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate \"Donate using Liberapay\")\n- - -\n\n- [Code of Conduct](./.github/CODE_OF_CONDUCT.md)\n- [Contributing](./.github/CONTRIBUTING.md)\n\u003c!-- - [Security Policy](./.github/SECURITY.md) --\u003e\n\n## Features\n- **Session persistence:** State persists across navigation, staying in sync with the browser's session history.\n- **Multi-tab synchronization:** Keeps state in sync across multiple tabs or windows on the same origin using `BroadcastChannel`.\n- **Efficient state updates:** Only updates when necessary, ensuring minimal performance overhead.\n- **Flexible API:** Includes utilities for observing state changes, managing key-specific states, and clearing state.\n\n## Installation\n```bash\nnpm install @aegisjsproject/state\n```\n\n## CDN and importmap\nYou do not even need to `npm install` this or use any build process. You may either import it directly from a CDN\nor use an [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap).\n\n```html\n\u003cscript type=\"importmap\"\u003e\n{\n  \"imports\": {\n    \"@aegisjsproject/state\": \"https://unpkg.com/@aegisjsproject/state[@version]/state.js\"\n  }\n}\n\u003c/script\u003e\n```\n\n## Example\n\n```js\nimport { setState, getState, observeStateChanges, manageState, watchState } from '@aegisjsproject/state';\n\n// Enables syncing of state across tabs/windows\nwatchState();\n\n// Set state\nsetState('key', 'value');\n\n// Get state\nconst value = getState('key');\n\n// Observe state changes\nobserveStateChanges(({ diff, state }) =\u003e {\n  console.log('State changed:', diff, state);\n});\n\n// Observe state changes to only specific state keys\nobserveStateChanges(({ state }) =\u003e {\n  console.log('State changed:', {\n    foo: state.foo,\n    bar: state.bar,\n  });\n}, 'foo', 'bar');\n\n// Manage state with reactive pattern\nconst [state, setStateValue] = manageState('key', 'defaultValue');\nconsole.log(state.valueOf());  // Logs the state value from the wrapper object\nsetStateValue('newValue');     // Updates the state\n```\n\n\u003e [!IMPORTANT]\n\u003e This is **NOT** to be confused with eg `useState()` in React or anything like that. There is no\n\u003e transpilation step involved. Although `manageState()` does return a tuple of `[value, setValue]`,\n\u003e it takes a key and an initial value, and the `value` is an object which wraps the current value.\n\u003e You can use the value via things like `setValue(value + 1)` thanks to `[Symbol.toPrimitive]`, however.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faegisjsproject%2Fstate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faegisjsproject%2Fstate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faegisjsproject%2Fstate/lists"}