{"id":19725968,"url":"https://github.com/dvdzkwsk/re-frame","last_synced_at":"2025-04-30T00:31:59.687Z","repository":{"id":84534644,"uuid":"162660401","full_name":"dvdzkwsk/re-frame","owner":"dvdzkwsk","description":"A VanillaJS take on Clojure's fantastic re-frame library","archived":false,"fork":false,"pushed_at":"2019-12-31T07:04:06.000Z","size":851,"stargazers_count":13,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T20:26:28.604Z","etag":null,"topics":["flux","javascript","re-frame","single-page-applications","state-management"],"latest_commit_sha":null,"homepage":"","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/dvdzkwsk.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-21T03:22:33.000Z","updated_at":"2023-11-17T18:05:08.000Z","dependencies_parsed_at":"2024-01-14T00:03:03.812Z","dependency_job_id":null,"html_url":"https://github.com/dvdzkwsk/re-frame","commit_stats":null,"previous_names":["dvdzkwsk/re-frame"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvdzkwsk%2Fre-frame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvdzkwsk%2Fre-frame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvdzkwsk%2Fre-frame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvdzkwsk%2Fre-frame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvdzkwsk","download_url":"https://codeload.github.com/dvdzkwsk/re-frame/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251607835,"owners_count":21616846,"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":["flux","javascript","re-frame","single-page-applications","state-management"],"created_at":"2024-11-11T23:33:56.310Z","updated_at":"2025-04-30T00:31:59.192Z","avatar_url":"https://github.com/dvdzkwsk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# re-frame\n\n[![Build Status](https://travis-ci.com/davezuko/re-frame.svg?branch=master)](https://travis-ci.com/davezuko/re-frame)\n[![Bundle Size](https://badgen.net/bundlephobia/minzip/@re-frame/core)](https://bundlephobia.com/result?p=@re-frame/core)\n\nVanilla JavaScript port of the popular [ClojureScript library](https://github.com/Day8/re-frame) for pragmatic, flux-like state management. I highly recommend checking out re-frame's [original documentation](https://github.com/Day8/re-frame/blob/master/docs/INTRO.md) to learn about its philosophy, terminology, and patterns. All design credit goes to the original authors — thank you for the inspiration.\n\n## Why re-frame?\n\nRe-frame helps make state management predictable, testable, and pragmatic. It achieves this via message passing, which decouples action from intent. On top of this, it provides [first-class semantics](./docs/effects.md) for dealing with side-effects, as these are unavoidable in real-world applications.\n\nFrom a high-level, re-frame is flux-like with events and event handlers, which are similar to redux's actions and reducers. [Compared to redux](./docs/re-frame-vs-redux.md), re-frame is more feature complete out of the box, with built-in interceptors, effects, subscriptions, and test utilties. You'll find that you can be productive without needing to reach for third-party middleware.\n\n## Getting Started\n\nThe quickest way to get started is by installing `@re-frame/standalone`, which bundles everything you'll need to build a typical application: a store to manage state, subscriptions to query it, effects such as [http](./docs/effects.md#http), [orchestrate](./docs/effects.md#orchestrate), and more since the real world is more complicated than TodoMVC.\n\n```sh\nyarn add @re-frame/standalone\n```\n\nOnce you've become familiar with re-frame, feel free to install only the packages you need to cut down on install size. You'll need @re-frame/store to create a store, but everything else is optional.\n\n| Package                                                     | Description                                                  |\n| ----------------------------------------------------------- | ------------------------------------------------------------ |\n| [@re-frame/store](./packages/store/README.md)               | Creates a re-frame store (ergonomic API over @re-frame/core) |\n| [@re-frame/core](./packages/core/README.md)                 | Low-level store API                                          |\n| [@re-frame/effects](./packages/effects/README.md)           | Useful effects for most web apps (HTTP, orchestrate, etc.)   |\n| [@re-frame/interceptors](./packages/interceptors/README.md) | Common interceptors (path, immer, debug, etc.)               |\n| [@re-frame/react](./packages/react/README.md)               | React bindings (useDispatch, useSubscription)                |\n| [@re-frame/preact](./packages/preact/README.md)             | Preact bindings (useDispatch, useSubscription)               |\n| [@re-frame/global](./packages/global/README.md)             | A global re-frame store instance                             |\n\n## Usage\n\nBelow is an example that shows how to create a store, define event handlers, setup and access subscriptions, and run side effects. For now, you should refer to the original re-frame documentation for best practices.\n\nUnlike the original re-frame library which uses a singleton store, the JavaScript package provides an API for creating your own independent stores. If you want the convenience of a global store, use @re-frame/global.\n\n```js\nimport {createStore} from \"@re-frame/store\"\n\nconst store = createStore()\n```\n\nA store holds application state in an object called \"db\" (it's your in-memory database). To make updates to the db, you register and dispatch events:\n\n```js\n// Define event handlers:\nstore.event(\"init\", (db, event) =\u003e ({count: 0}))\nstore.event(\"increment\", (db, event) =\u003e ({count: db.count + 1}))\n\n// Send events to the store:\nstore.dispatch(\"init\")       // db = { count: 0 }\nstore.dispatch(\"increment\")  // db = { count: 1 }\nstore.dispatch(\"increment\")  // db = { count: 2 }\n\n// Pass data with events:\nstore.event(\"add\", (db, { amount }) =\u003e ({ count: db.count + amount }))\nstore.dispatch(\"add\", { amount: 5 })\n```\n\nTo access the db, register queries with the store. All active queries are recomputed every time the db changes, and are only recomputed once per change regardless of how many subscribers exist.\n\n```js\nstore.computed(\"count\", db =\u003e db.count)\n\nconst count = store.subscribe(\"count\")\n\nstore.dispatchSync(\"init\")       // db = { count: 0 }\ncount.deref()                    // 0\nstore.dispatchSync(\"increment\")  // db = { count: 1 }\ncount.deref()                    // 1\n\n// You can also watch a subscription to see all changes over time:\ncount.watch(value =\u003e { ... })\n\n// Cleanup your subscription when you're done with it.\ncount.dispose()\n\n// You can also pass parameters to the query:\nstore.computed(\"todos\", (db, { completed }) =\u003e {\n  return db.todos.filter(todo =\u003e todo.completed === completed)\n})\nstore.subscribe(\"todos\", { completed: false })\n```\n\nMost events will simply update the store's state. This update is one particular type of effect that events can have (appropriately called the \"db\" effect\"), and while most events will only update the db, you can step up a level and trigger any number of effects.\n\n```js\nimport {http} from \"@re-frame/effects\"\n\n// Register your effect with the store:\nstore.effect(\"http\", http)\n\n// Define an event handler that will trigger that effect:\nstore.event.fx(\"load-data\", (ctx, event) =\u003e ({\n  // Updates your store state (\"db\")\n  db: {\n    ...ctx.db,\n    loadingData: true,\n  },\n  // Also triggers an \"http\" effect to make a network request.\n  http: {\n    url: \"my.api.com/endpoint\",\n    method: \"GET\",\n    success: \"load-data-success\",\n    failure: \"load-data-failure\",\n  },\n}))\n\n// Initiate the effect:\nstore.dispatch(\"load-data\")\n```\n\n## Differences from Clojure's re-frame\n\n@re-frame's API provides the same conceptual ideas as the original re-frame library, with a few name changes to make them more compact and palatable to developers that are used to mobx and redux:\n\n| @re-frame/store API             | Clojure re-frame API                  |\n| ------------------------------- | ------------------------------------- |\n| `store.event(\"id\", handler)`    | `(re-frame/reg-event-db :id handler)` |\n| `store.event.fx(\"id\", handler)` | `(re-frame/reg-event-fx :id handler)` |\n| `store.effect(\"id\", handler)`   | `(re-frame/reg-fx :id handler)`       |\n| `store.computed(\"id\", handler)` | `(re-frame/reg-sub :id handler)`      |\n| `store.subscribe(\"id\", params)` | `(re-frame/subscribe [:id arg])`      |\n| `store.dispatch(\"id\", payload)` | `(re-frame/dispatch [:id arg])`       |\n\nLow-level store API:\n\n| @re-frame/core API                          | Clojure re-frame API                  |\n| ------------------------------------------- | ------------------------------------- |\n| `store.registerEventDB(\"id\", handler)`      | `(re-frame/reg-event-db :id handler)` |\n| `store.registerEventFX(\"id\", handler)`      | `(re-frame/reg-event-fx :id handler)` |\n| `store.registerEffect(\"id\", handler)`       | `(re-frame/reg-fx :id handler)`       |\n| `store.registerSubscription(\"id\", handler)` | `(re-frame/reg-sub :id handler)`      |\n| `store.subscribe({ id, arg })`              | `(re-frame/subscribe [:id arg])`      |\n| `store.dispatch({ id, arg })`               | `(re-frame/dispatch [:id arg])`       |\n\n## Supported Browsers\n\n| [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png\" alt=\"IE / Edge\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eIE / Edge | [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png\" alt=\"Firefox\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eFirefox | [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png\" alt=\"Chrome\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eChrome | [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png\" alt=\"Safari\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eSafari |\n| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| IE11, Edge                                                                                                                                                                                                      | last 2 versions                                                                                                                                                                                                   | last 2 versions                                                                                                                                                                                               | last 2 versions                                                                                                                                                                                               |\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 David Zukowski\u003cbr /\u003e\nCopyright (c) 2015-2017 Michael Thompson\u003cbr /\u003e\nCopyright (c) 2017 Evgeny Poberezkin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvdzkwsk%2Fre-frame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvdzkwsk%2Fre-frame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvdzkwsk%2Fre-frame/lists"}