{"id":20452829,"url":"https://github.com/axtk/store","last_synced_at":"2025-03-05T09:47:13.488Z","repository":{"id":57100093,"uuid":"292705766","full_name":"axtk/store","owner":"axtk","description":"A lightweight shared state manager","archived":false,"fork":false,"pushed_at":"2021-12-04T22:57:47.000Z","size":153,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T09:45:53.304Z","etag":null,"topics":["shared-state","store"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/axtk.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}},"created_at":"2020-09-04T00:00:44.000Z","updated_at":"2021-12-04T22:57:49.000Z","dependencies_parsed_at":"2022-08-22T23:10:46.262Z","dependency_job_id":null,"html_url":"https://github.com/axtk/store","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fstore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fstore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fstore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fstore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axtk","download_url":"https://codeload.github.com/axtk/store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242005698,"owners_count":20056430,"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":["shared-state","store"],"created_at":"2024-11-15T11:10:31.045Z","updated_at":"2025-03-05T09:47:13.455Z","avatar_url":"https://github.com/axtk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/@axtk/store?labelColor=royalblue\u0026color=royalblue\u0026style=flat-square)](https://www.npmjs.com/package/@axtk/store) [![GitHub](https://img.shields.io/badge/-GitHub-royalblue?labelColor=royalblue\u0026color=royalblue\u0026style=flat-square\u0026logo=github)](https://github.com/axtk/store) ![browser](https://img.shields.io/badge/browser-✓-345?labelColor=345\u0026color=345\u0026style=flat-square) ![node](https://img.shields.io/badge/node-✓-345?labelColor=345\u0026color=345\u0026style=flat-square) ![TypeScript](https://img.shields.io/badge/TypeScript-✓-345?labelColor=345\u0026color=345\u0026style=flat-square)\n\n# @axtk/store\n\n_A lightweight storage for shared state_\n\nAn instance of the `Store` class is a lightweight container for data, which:\n- exposes a set of methods to manipulate the stored data (like `.set(keyPath, data)`, `.get(keyPath)`), and\n- allows for subscriptions to updates it receives (via `.onUpdate(handler)`).\n\nAs an example, instances of the `Store` class can be used as a storage for shared state in React applications. See also *[react-store](https://github.com/axtk/react-store)* that adds a React hook for shared state management based on the `Store` class.\n\n## Store API\n\n### Initialization\n\n```js\nimport {Store} from '@axtk/store';\n\nconst store = new Store();\n// With an initial state:\n// const store = new Store({location: {x: -1, y: 1}});\n```\n\nThe setters and getters below make use of the key paths to access the nested values. With TypeScript, the key paths, the arguments, and the return values are automatically checked to match the type of the store state.\n\n### Setters\n\n```js\nstore.setState({location: {x: 1, y: 0}});\n```\n\n```js\nstore.set('location', {x: -1, y: 1});\nstore.set(['location', 'x'], 1);\n```\n\n### Getters\n\n```js\nlet state = store.getState();\n```\n\n```js\nlet location = store.get('location');\nlet y = store.get(['location', 'y']);\n// With a default value:\nlet z = store.get(['location', 'z'], 0);\n```\n\n### Subscription\n\n```js\nlet unsubscribe = store.onUpdate(store =\u003e {\n    console.log('updated');\n});\n```\n\n```js\nunsubscribe(); // to remove the subscription\n```\n\n### Removal\n\n```js\nstore.removeState();\n```\n\n```js\nstore.remove('location');\nstore.remove(['location', 'y']);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fstore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxtk%2Fstore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fstore/lists"}