{"id":32183760,"url":"https://github.com/oconn/re-frame-request","last_synced_at":"2025-10-21T23:07:21.785Z","repository":{"id":26771534,"uuid":"108678306","full_name":"oconn/re-frame-request","owner":"oconn","description":"A ClojureScript library that tracks request state in re-frame applications.","archived":false,"fork":false,"pushed_at":"2021-09-30T19:01:33.000Z","size":34,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-21T23:03:09.388Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oconn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-10-28T19:34:00.000Z","updated_at":"2021-12-01T18:45:00.000Z","dependencies_parsed_at":"2022-08-07T12:00:56.203Z","dependency_job_id":null,"html_url":"https://github.com/oconn/re-frame-request","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/oconn/re-frame-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oconn%2Fre-frame-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oconn%2Fre-frame-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oconn%2Fre-frame-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oconn%2Fre-frame-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oconn","download_url":"https://codeload.github.com/oconn/re-frame-request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oconn%2Fre-frame-request/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280348066,"owners_count":26315368,"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-10-21T02:00:06.614Z","response_time":58,"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":"2025-10-21T23:02:41.950Z","updated_at":"2025-10-21T23:07:21.780Z","avatar_url":"https://github.com/oconn.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# re-frame-request\n\nA ClojureScript library that tracks request state in [re-frame](https://github.com/Day8/re-frame) applications.\n\n## Install\n\n[![Clojars Project](https://img.shields.io/clojars/v/oconn/re-frame-request.svg)](https://clojars.org/oconn/re-frame-request)\n\n## Usage\n\n### Register Events and Subscriptions\n\nEvents and subscriptions can be registered seperatly;\n\n```cljs\n(ns app.events\n  (:require [re-frame-request.core :as rfr]))\n\n(rfr/register-events)\n```\n\n```cljs\n(ns app.subscriptions\n  (:require [re-frame-request.core :as rfr]))\n\n(rfr/register-subscriptions)\n```\n\nOr you can use the `register-all` function to register both subscriptions \u0026 events.\n\n```cljs\n(ns app.core\n  (:require [re-frame-request.core :as rfr]))\n\n(rfr/register-all)\n```\n\n### Request data\n\nOnce an event is dispatched that calls the `re-frame-request` handler, information about that request will automatically be tracked in application state. Here is an example of an event that uses `re-frame-request`.\n\n```cljs\n(re-frame/reg-event-fx\n :github/get-user\n (fn [{:keys [db]} [_ user-name]]\n   {:db db\n    :request {:name :github/get-user\n              :method :get\n              :uri (str \"https://api.github.com/userss/\" user-name)\n              :response-format (json-response-format)\n              :on-success [:no-op]\n              :on-error [:no-op]}}))\n```\n\nNote: This uses the `ajax-cljs` under the hood so reference the [docs](https://github.com/JulianBirch/cljs-ajax) for usage.\n\n#### `name`\n\nThe `name` property is the only added property used and is required to track a request. It must be a unique keyword for each different request.\n\n### Register Spec Checks (Optional)\n\nOn applcation state change, `re-frame` [interceptors](https://github.com/Day8/re-frame/blob/master/docs/Interceptors.md) can be used to ensure an application's state is not modified in an unexpected way. By hooking into an interceptor's [after](https://github.com/Day8/re-frame/blob/master/docs/Interceptors.md#executing-a-chain) function, a user could apply `re-frame-request`s [spec](https://clojure.org/guides/spec) to help maintain application state integrity.\n\n#### 1. Add Spec Interceptor\n\nThis idea was inspired by the great folks who wrote `re-frame`. [Link](https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/events.cljs#L9)\n\n```cljs\n(ns app.interceptors.spec\n  (:require [cljs.spec.alpha :as s]\n            [re-frame.core :as re-frame]))\n\n(def ^:private attribution\n  \"https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc\")\n\n(defn check-and-throw\n  ^{:doc \"Throws an exception if `db` doesn't match the Spec `a-spec`.\"\n    :attribution attribution}\n  [a-spec db]\n  (when-let [error (s/explain-data a-spec db)]\n    (js/console.error (clj-\u003ejs error))))\n\n(def\n  ^{:doc \"Ensures the db remains in a valid state\"\n    :attribution attribution}\n  check-spec-interceptor (re-frame/after\n                          (partial check-and-throw :app.db.core/db)))\n```\n\n#### 2. Use Spec Interceptor\n\nAdd the spec checking interceptor any event you want to enforce checks on.\n\n```cljs\n(ns app.events.event-ns\n  (:require [app.interceptors.spec :refer [check-spec-interceptor]])\n\n(re-frame/reg-event-db\n  :app-event/some-event\n  [[check-spec-interceptor]]\n  (fn [db _]\n    (modify-db db))\n```\n\nNote: Because the way this is setup, you'll be running spec against your entire application state on each change, which could be costly. You may want this feature to be toggled depending on the environment you're running in (Development / QA / Production).\n\n## License\n\nCopyright © 2017 Matt O'Connell\n\nDistributed under the Eclipse Public License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foconn%2Fre-frame-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foconn%2Fre-frame-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foconn%2Fre-frame-request/lists"}