{"id":13605330,"url":"https://github.com/choojs/choo-store","last_synced_at":"2026-03-07T18:04:50.045Z","repository":{"id":57198235,"uuid":"130748192","full_name":"choojs/choo-store","owner":"choojs","description":"Lightweight state structure for choo apps.","archived":false,"fork":false,"pushed_at":"2020-10-09T05:54:00.000Z","size":34,"stargazers_count":37,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-22T01:53:29.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/choojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-23T19:45:12.000Z","updated_at":"2023-02-26T01:44:10.000Z","dependencies_parsed_at":"2022-09-16T13:12:32.853Z","dependency_job_id":null,"html_url":"https://github.com/choojs/choo-store","commit_stats":null,"previous_names":["ungoldman/choo-store"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/choojs/choo-store","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choojs%2Fchoo-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choojs%2Fchoo-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choojs%2Fchoo-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choojs%2Fchoo-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/choojs","download_url":"https://codeload.github.com/choojs/choo-store/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/choojs%2Fchoo-store/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30225486,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T17:00:40.062Z","status":"ssl_error","status_checked_at":"2026-03-07T17:00:39.026Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-08-01T19:00:57.477Z","updated_at":"2026-03-07T18:04:50.030Z","avatar_url":"https://github.com/choojs.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# choo-store [![stability][0]][1]\n\n[![npm version][2]][3] [![build status][4]][5]\n[![downloads][8]][9] [![js-standard-style][10]][11]\n\nCreate a store for a [`choo`](https://github.com/choojs/choo) application.\n\n[0]: https://img.shields.io/badge/stability-stable-brightgreen.svg?style=flat-square\n[1]: https://nodejs.org/api/documentation.html#documentation_stability_index\n[2]: https://img.shields.io/npm/v/choo-store.svg?style=flat-square\n[3]: https://npmjs.org/package/choo-store\n[4]: https://img.shields.io/travis/choojs/choo-store/master.svg?style=flat-square\n[5]: https://travis-ci.org/choojs/choo-store\n[8]: http://img.shields.io/npm/dm/choo-store.svg?style=flat-square\n[9]: https://npmjs.org/package/choo-store\n[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[11]: https://github.com/feross/standard\n\n## Features\n\n- **namespacing**: use [`storeName`](https://github.com/choojs/choo#appusecallbackstate-emitter-app) to keep state clean and improve tracing\n- **scoped state**: set `initialState` to make initializing and resetting easy\n- **simplified events API**: organize all your `events` to reduce boilerplate\n- **action functions**: automagically creates `actions` that accept data and emit events\n- **event names in state**: event names made available in `state.events.storeName`\n- **free reset event**: free `reset` event included with purchase\n\n## Install\n\n```\nnpm install choo-store\n```\n\n## Usage\n\nFirst, set up your store's name, initial state, and events:\n\n```js\nvar createStore = require('choo-store')\n\nmodule.exports = createStore({\n  storeName: 'clicks',\n  initialState: { count: 0 },\n  events: {\n    increment: ({ store, emitter }) =\u003e {\n      store.count++\n      emitter.emit('render')\n    }\n  }\n})\n```\n\nNext, register your store with your choo app:\n\n```js\nvar app = require('choo')()\nvar store = require('./stores/clicks')\n\napp.use(store)\n```\n\nNow you can use store state and actions in your component:\n\n```js\nvar html = require('choo/html')\nvar { actions } = require('./stores/clicks')\n\nmodule.exports = ({ clicks }) =\u003e {\n  return html`\n    \u003cbody\u003e\n      \u003ch1\u003ecount is ${clicks.count}\u003c/h1\u003e\n      \u003cbutton onclick=${e =\u003e actions.increment(1)}\u003eIncrement\u003c/button\u003e\n      \u003cbutton onclick=${e =\u003e actions.reset({ render: true })}\u003eReset\u003c/button\u003e\n    \u003c/body\u003e\n  `\n}\n```\n\n### Example\n\nSee the [`example`](./example) folder for a full working example.\n\nYou can also check it out locally by cloning this repo and running `npm i \u0026\u0026 npm run example`.\n\n## API\n\n### `createStore({ storeName, initialState, events })`\n\nParams:\n\n- `storeName` - *string*: Name of store. Used for namespacing in state object and prefixing of event names.\n- `initialState` - *object*: Initial state of store.\n  - This will be the state of the store on initialization of the app.\n  - When calling the `reset` event, state will be returned to this value.\n  - Must be valid, serializable JSON\n- `events` - *object*: List of named event functions.\n\nAll params are required.\n\nReturns a regular store function (`function (state, emitter, app)`) to be supplied to Choo's `app.use()` function.\n\nAttaches event names to `state.events[storeName]` for convenience. For example, if you have a store `clicks` with an event `increment`, the event name (`clicks:increment`) will be available at `state.events.clicks.increment`.\n\nReturned function also has an `actions` property containing ready-to-go named functions that take whatever data you pass and emit the right event.\n\n### Event Functions\n\nEvent functions live in the `events` object and have the following signature:\n\n```js\nfunction eventName ({ data, store, state, emitter, app }) {}\n```\n\nParams:\n\n- `data` - *any*: Event data supplied by user.\n- `store` - *object*: Local store state.\n- `state` - *object*: Global app state.\n- `emitter` - *[nanobus](https://github.com/choojs/nanobus)*: Choo event emitter.\n- `app` - *[choo](https://github.com/choojs/choo)*: Choo instance.\n\nParams are wrapped in a single object so that argument order is made irrelevant and users can take what they need from the event parameters object.\n\n### Emitting Events\n\nOnce a store has been created, these three methods of emitting an event all do the same thing:\n\n```js\nstore.actions.increment(1)\nemit(state.events.clicks.increment, 1)\nemit('clicks:increment', 1)\n```\n\n### Global Events\n\nYou can listen for any of Choo's global events (`DOMContentLoaded`, `DOMTitleChange`,\n`navigate`, `popState`, `pushState`, `render`, `replaceState`) by adding an event\nwith the appropriate name to the `events` object:\n\n```js\ncreateStore({\n  storeName: 'history',\n  initialState: { navigations: 0 },\n  events: {\n    navigate: ({ store, emitter }) =\u003e {\n      store.navigations++\n      emitter.emit('render')\n    }\n  }\n})\n```\n\n\u003e Note: global events are not added to `state.events[storeName]` and do not have\nan action function associated with them since they are not namespaced events.\n\n### `reset` event\n\nA `reset` event (e.g. `storeName:reset`) is added by default.\n\nEmitting this event will reset the store's state to `initialState`.\n\nIt takes a `render` boolean option in case you want to emit a render event afterwards.\n\n```js\nstore.actions.reset({ render: true })\n```\n\n## Why\n\n**Q: Choo has a decent way to create a store already. Why use this?**\n\n**A: Bigger apps need more structure!**\n\nAs an application gets larger, some issues can arise that need to be dealt with:\n\n- properly namespacing stores and events\n- resetting stores to their initial state\n- avoiding direct manipulation of other stores\n- providing coherent structure for a project\n- reducing repetitive boilerplate\n\nDoing the above gets time consuming the bigger an app gets. Without lots of attention to detail, it's easy to lose track of [value drift](https://universalpaperclips.gamepedia.com/Value_Drift) between stores in these cases. This module aims to make the process of managing stores and events simple and easy.\n\n## Contributing\n\nContributions welcome! Please read the [contributing guidelines](CONTRIBUTING.md) before getting started.\n\n## License\n\n[ISC](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchoojs%2Fchoo-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchoojs%2Fchoo-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchoojs%2Fchoo-store/lists"}