{"id":26769899,"url":"https://github.com/bbuck/nuka-state","last_synced_at":"2025-03-28T22:46:22.092Z","repository":{"id":57132369,"uuid":"361220759","full_name":"bbuck/nuka-state","owner":"bbuck","description":"State management that can survive the fallout. https://bbuck.github.io/nuka-state","archived":false,"fork":false,"pushed_at":"2021-05-15T18:38:58.000Z","size":302,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T15:06:55.905Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/bbuck.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-04-24T17:10:07.000Z","updated_at":"2022-01-04T08:47:55.000Z","dependencies_parsed_at":"2022-09-02T11:10:25.798Z","dependency_job_id":null,"html_url":"https://github.com/bbuck/nuka-state","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuck%2Fnuka-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuck%2Fnuka-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuck%2Fnuka-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbuck%2Fnuka-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbuck","download_url":"https://codeload.github.com/bbuck/nuka-state/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246112648,"owners_count":20725300,"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":[],"created_at":"2025-03-28T22:46:21.674Z","updated_at":"2025-03-28T22:46:22.086Z","avatar_url":"https://github.com/bbuck.png","language":"TypeScript","readme":"# @nuka/state\n\n## Installation\n\nInsteall using your preferred package manager.\n\n```\n$ npm install -P @nuka/state\n```\n\n```\n$ yarn add @nuka/state\n```\n\n```\n$ pnpm add @nuka/state\n```\n\nOnce `@nuka/state` is installed you can use it by importing the atom tools that\nyou want to use:\n\n```typescript\nimport { atom, reactor, projector } from '@nuka/state';\n\nconst count = atom(0);\n\nconst counter = reactor(atom(0), {\n\tincrement: value =\u003e value + 1,\n});\n\nconst binary = projector(count, value =\u003e value.toString(2));\n```\n\n[Try it out on CodePen!](https://codepen.io/bbuck/pen/BaWzzMv)\n\n## Description\n\n`@nuka/state` is an application state-management library that focus on small\nunits of state instead of large chunks of global state. The idea is that small\nstate changes should not affect parts of a project that don't care/depend on\nthose changes. This is accomplished with the **atom**, the smallest unit of state\nstorage in `@nuka/state`. You encapsulate your state values in an **atom** and then\nyou can use the value anywhere in your project. Combine that with subscribing\nto the item to be notified when the value is modified and you can react to\nstate changes no matter when or where they occur.\n\nHere is a simple counter example:\n\n```javascript\nimport { atom } from '@nuka/state';\n\n// This is the magic, counter is now an atom and ready to be used.\nconst counter = atom(0);\n\nconst countDisplay = document.querySelector('#count-display');\n// subscribe functions receive the atom as their argument allowing for flexible\n// definition patterns\ncounter.subscribe(atom =\u003e {\n\tcountDisplay.textContent = `Current count: ${atom.value}`;\n});\n\nconst incrementButton = document.querySelector('#increment-button');\n// update receives the current value and should return the next new value,\n// updates are queued and fired in order so multiple increments back to back\n// will not cause any race conditions modifying the value.\nincrementButton.addEventListener('click', () =\u003e counter.update(n =\u003e n + 1));\n```\n\n[Try it out on CodePen!](https://codepen.io/bbuck/pen/yLgwBGL?editors=0010)\n\n## Roadmap\n\n- [x] Project setup (mostly done, maybe some minor cleanup here and there)\n- [x] BaseAtom (base implementation for an atom)\n- [x] ReadonlyAtom (readonly atom implementation with dynamic update options)\n- [x] Atom (mostly implemented, basic core library feature)\n- [ ] more documentation\n- [ ] more tests\n- [ ] Product (a combination of several atoms into a single atom-like structure)\n  - [ ] array Product\n  - [ ] object Product\n- [x] Reactor (a atom-like wrapper around atoms that provide named actions for\n      use.\n- [x] Projector (an atom-like structure that takes one or more atoms and provides\n      a different value, such as taking two count atoms and providing their\n      sum as it's value).\n- [x] Publish to NPM\n- [ ] (Sister project) React hook bindings allowing components to respond to\n      atom updates.\n- [ ] (Sister project) DOM tools to simplify working with atoms and native DOM\n      APIs.\n\n## Contributing\n\nContributions are totally welcome and greatly appreciated. In order to contribute\nplease follow these simple steps:\n\n1. Find or create an issue detailing the problem you're looking to solve.\n1. Fork `nuka-state` and create a branch for your work.\n1. Solve the problem (this step could be hard!)\n1. Commit your work and create a pull request against the `develop` branch\n1. Wait for a review from an existing maintainer or contributor\n1. Enjoy the fruits of your labor as your work has been merged (there may be a\n   delay between merging the PR and it being published on NPM)!\n\n# Contributors\n\nBrandon Buck / @bbuck (Creator/maintainer)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbuck%2Fnuka-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbuck%2Fnuka-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbuck%2Fnuka-state/lists"}