All Projects → oconn → re-frame-routing

oconn / re-frame-routing

Licence: EPL-1.0 license
ClojureScript (re-frame) library that manages routing and route state.

Programming Languages

clojure
4091 projects
shell
77523 projects
HTML
75241 projects

Projects that are alternatives of or similar to re-frame-routing

Boodle
Accounting SPA in Clojure and ClojureScript
Stars: ✭ 183 (+1043.75%)
Mutual labels:  re-frame
rn-shadow-steroid
React Native with shadow-cljs on steroids
Stars: ✭ 57 (+256.25%)
Mutual labels:  re-frame
sitefox
Node + cljs backend web framework
Stars: ✭ 180 (+1025%)
Mutual labels:  clojurescript-library
rough-cljs
A data-driven, reagent wrapper for RoughJS
Stars: ✭ 16 (+0%)
Mutual labels:  clojurescript-library
re-flow
A library that adds tools for building and executing workflows in re-frame applications
Stars: ✭ 31 (+93.75%)
Mutual labels:  re-frame
breaking-point
BREAKING-POINT lets you quickly define and subscribe to screen (i.e. window) breakpoints in your re-frame application
Stars: ✭ 36 (+125%)
Mutual labels:  re-frame
Mecca
Animated music editor in Clojurescript/re-frame
Stars: ✭ 125 (+681.25%)
Mutual labels:  re-frame
ClojureRNProject
Simple React Native application with ClojureScript, re-frame and react navigation v5
Stars: ✭ 32 (+100%)
Mutual labels:  re-frame
re-frame-tracer
No description or website provided.
Stars: ✭ 15 (-6.25%)
Mutual labels:  re-frame
re-pressed
re-pressed is a clojurescript library that handles keyboard events for re-frame applications.
Stars: ✭ 150 (+837.5%)
Mutual labels:  re-frame
re-frame-semantic-ui-react-github-widget
Using semantic-ui-react with re-frame - sample project
Stars: ✭ 21 (+31.25%)
Mutual labels:  re-frame
re-frame-realword-example-app
Exemplary real world application built with Clojurescript and re-frame
Stars: ✭ 16 (+0%)
Mutual labels:  re-frame
roll
RPG dice roller with both Rust CLI and ClojureScript Web interfaces
Stars: ✭ 14 (-12.5%)
Mutual labels:  re-frame
Re Frame Http Fx
A re-frame "effects handler" for performing Ajax tasks (via cljs-ajax)
Stars: ✭ 193 (+1106.25%)
Mutual labels:  re-frame
tailwind-hiccup
tailwindcss + hiccup = 👍👍
Stars: ✭ 34 (+112.5%)
Mutual labels:  re-frame
Re Frame Async Flow Fx
A re-frame effects handler for coordinating the kind of async control flow which often happens on app startup.
Stars: ✭ 150 (+837.5%)
Mutual labels:  re-frame
compound
A micro structure for reframe data
Stars: ✭ 116 (+625%)
Mutual labels:  re-frame
re-alm
An Elm Architecture experiment in ClojureScript
Stars: ✭ 24 (+50%)
Mutual labels:  re-frame
re-frame-utils
Re-frame extensions
Stars: ✭ 59 (+268.75%)
Mutual labels:  re-frame
learn-re-frame-course-files
🎦 Learn re-frame course files for building Cheffy app
Stars: ✭ 51 (+218.75%)
Mutual labels:  re-frame

re-frame-routing

ClojureScript (re-frame) library that manages routing and route state.

re-frame-routing is built on top of bidi and persists route state to re-frame's app state. Registering re-frame-routing to an existing re-frame application is ease.

Step 1: Install

Clojars Project

CircleCI

Step 2: Import Events

(ns app.events.core
  (:require [re-frame-routing.core :as rfr]

            [app.router.core :as router]))

(rfr/register-events {:routes router/routes})

Step 3: Import Subscriptions

(ns app.subscriptions.core
  (:require [re-frame-routing.core :as rfr]))

(rfr/register-subscriptions)

Route Middleware

(Note this API is subject to change in future releases)

Pre Dom Render Loading

Sometimes it's nice to perform work when a route is loading, maybe even prevent the route's view from displaying until that work is done, or even redirect if a user does not have access to view the route. These are good use cases for route-middleware.

To add route-middleware to a route, first create the route-middleware function

(def route-middleware
  (rfr/create-route-middleware {:loading-view loading/render}))

loading-view is a reagent component that will display while your route is loading.

Now let's say you have a sign-in page, but only unauthenticated users should be able to view it. Here is you sign-in route with no middleware

(defmethod containers :sign-in []
  [sign-in/render])

And now we add some middleware

(defmethod containers :sign-in []
  [(route-middleware
    sign-in/render
    [redirect-authenticated])])

Without diving into redirect-authenticated quite yet, let's first look at our route-middleware function. It takes in a view component and a vector of middleware functions (executed from left to right). The result after all functions have executed is the view. The view will receive path and query params as arguments.

Next let's look at redirect-authenticated

(defn redirect-authenticated
  "Redirects authenticated users to the authenticated home page"
  [{:keys [route-query route-params] :as ctx}]
  (let [is-authenticated (re-frame/subscribe [:user/is-authenticated?])]

    (when (true? @is-authenticated)
      (re-frame/dispatch [:router/nav-to "/authenticated-home"]))

    (if (true? @is-authenticated)
      (assoc ctx :is-loading true)
      ctx)))

Middleware functions will be passed a context object and are expected to return a context object. To prevent the execution of the next middleware function in the chain, toggle the is-loading property on the middleware context object to true.

Route Coercion

Given data sent to the servers and to the component originates from information synced in the url (path and query params), it's ideal to have a way to share concerns over configuration (coercion and defaults). The library supports that concern by allowing you to supply an routes-enirched tree where leafs can be supplied a configuration instead of a keyword. e.g

{:query {:site {:coercion int?}
         :role {:coercion int?}
         :learner {:coercion #{"least-ready" "most-ready" "highest-mindset" "lowest-mindset"}
                   :default "least-ready"}
         :current-page {:coercion int?
                :default 0}}}

this will then provide a route-parameters map to the component. e.g

{:route-parameters {:role 1 :learner "least-ready" :site 2 :current-page 0}}

This functionality is then handled by spec-tools. Overall this is a less feature rich version of what's provided by reitit.

Development

Run clj -M:shadow-cljs watch app to and get a watched build. See Shadow cljs docs for more.

License

Copyright © 2018 Matt O'Connell

Distributed under the Eclipse Public License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].