Skip to content

Respo/respo-router.cljs

Repository files navigation

Respo Router

This project is experimental...

Demo http://router.respo-mvc.org/

Usage

Clojars Project

[respo/router "0.4.0"]
[respo-router.listener :refer [listen!]]
[respo-router.parser :refer [parse-address]]
[respo-router.format :refer [strip-sharp]]
[respo-router.core :refer [render-url!]]
; router rules
(def dict
 {"room" ["room-id"]
  "team" ["team-id"]
  "search" []})

; :hash | :history
(def mode :history)

; listen to router and dispatch actions
(listen! dict dispatch! mode)

; /a/b?c=d
(parse-address path dict)

; render url
(add-watch *store :changes
  (fn [] (render-url! (:router @*store) dict mode)))

Router IR

Based on a dict:

(def dict {"team" ["team-id"]
           "room" ["room-id"]
           "search" []})

Router data structure for:

/team/t12345/room/r1234?a=1&b=2

looks like:

{:path [{:name "team", :data {"team-id" "t12345"}}
        {:name "room", :data {"room-id" "r1234"}}],
 :query {"a" 1, "b" 2}}

Some special routes:

  • [] represents /
  • 404 is generated when no route is matched

Develop

yarn watch
# another terminal
yarn dev
# open http://localhost:8080

https://github.com/mvc-works/calcit-workflow

Test

yarn compile-test
node target/test.js

License

MIT