Overview¶
The re-frame API consists of:
- the namespace
re-frame.core— the stable, value-position-safe function API. All registration entry points (reg-event-*,reg-sub,reg-fx,reg-cofx) and dispatch / subscribe aredefns, so(map reg-event-db ...),(apply reg-sub ...),(partial reg-fx ...)work as written. - the namespace
re-frame.core-instrumented— opt-in macro mirror with the same call shape, plus call-site{:file :line}source-meta captured at macro-expansion time. A perfect drop-in forre-frame.core— safe in production builds (the macro path elides cleanly undergoog.DEBUG=false). Use it whenever you want handler provenance on dispatched events, subscription queries, or registered handlers; reach forre-frame.coreonly at the call sites that need higher-order use (e.g.(apply reg-sub ...),(map reg-event-db ...)). - a set of built-in effects
In the navigation to the left, you'll see a link to both.
Dependency Information¶
Please review both the releases page and the Clojars page to discover the version you should be using.
Using re-frame¶
To use the re-frame API within your namespace, you'll
need to require it, perhaps like this:
(ns my-app.some-namespace
(:require [re-frame.core :as rf]))
;; your code here
You'll then be able to use the functions in the API, perhaps like this: rf/dispatch.
The Most Commonly Used Part Of The API¶
When you are dispatching events:
dispatch(or occasionally,dispatch-sync)dispatch-with/dispatch-sync-withwhen you want selected effect handlers stubbed for one dispatchdispatch-and-settlewhen tests or diagnostics need to wait for a dispatch cascade to finish
When you are writing View Functions:
subscribe
When you are registering:
- event handlers -
reg-event-dbandreg-event-fx - subscription handlers -
reg-sub(and rarelyreg-sub-raw) - rarely, effect handlers -
reg-fx - rarely, coeffect handlers -
reg-cofxwithinject-cofx
When you register event handlers, you might use builtin interceptors:
pathon-changeenrichaftertrim-vdebug
Global interceptors can be very useful:
- register them via
reg-global-interceptors - rarely, remove them via
clear-global-interceptor
When errors arise:
- Catch them from events and interceptors via
reg-event-error-handler
Diagnostics & Instrumentation¶
Programmatic tooling can use these APIs without reaching into private implementation details:
versionreports the running re-frame artifact version.live-query-vsreturns a snapshot of every currently-live subscription query vector.query-v-for-reactionreturns the query vector that produced a known reaction.register-trace-cbandremove-trace-cbsubscribe to the raw trace stream.register-epoch-cbandremove-epoch-cbsubscribe to assembled per-dispatch epoch records.tag-schemadocuments the trace:tagscontract for downstream tooling.validate-trace?,set-validate-trace!, andcheck-trace-against-schemaprovide opt-in trace tag validation for development and CI.
See Debugging & Instrumentation and re-frame.tooling for the longer-form story.
Source-meta Macros¶
re-frame.core-instrumented is an opt-in macro mirror for diagnostics that need
call-site {:file :line} metadata on dispatched events, subscription
queries, or registered handlers:
(ns my-app.some-namespace
(:require [re-frame.core-instrumented :as rf]))
The macros have the same call shape as their re-frame.core counterparts
(dispatch, dispatch-sync, subscribe, reg-event-db,
reg-event-fx, reg-event-ctx, reg-sub, and reg-fx). In DEBUG builds
they attach :re-frame/source metadata; in production CLJS builds the
metadata path is removed by Closure dead-code elimination.
More Rarely Used Part¶
Testing or dev-time related utilities:
clear-subscription-cache!make-restore-fnpurge-event-queue
Logging/debugging:
consoleset-loggers
If you write an Interceptor, use these utilities. To see how they are used, look at the re-frame code for builtin Interceptors:
->interceptorget-coeffectassoc-coeffectget-effectassoc-effectenqueue