mirror of
https://github.com/metosin/reitit.git
synced 2025-12-22 02:21:11 +00:00
Public docs for reitit.segment
This commit is contained in:
parent
6bd005acbb
commit
75065b56e3
1 changed files with 13 additions and 9 deletions
|
|
@ -48,16 +48,20 @@
|
||||||
;; public api
|
;; public api
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defn insert [root path data]
|
(defn insert
|
||||||
#?(:cljs (-insert (or root (segment)) (impl/segments path) (map->Match {:data data}))
|
"Returns a Segment Trie with path with data inserted into it. Creates the trie if `nil`."
|
||||||
:clj (.add (or ^SegmentTrie root ^SegmentTrie (SegmentTrie.)) ^String path data)))
|
[trie path data]
|
||||||
|
#?(:cljs (-insert (or trie (segment)) (impl/segments path) (map->Match {:data data}))
|
||||||
|
:clj (.add (or ^SegmentTrie trie ^SegmentTrie (SegmentTrie.)) ^String path data)))
|
||||||
|
|
||||||
(defn compile [segment]
|
(defn compile [trie]
|
||||||
#?(:cljs segment
|
"Compiles the Trie so that [[lookup]] can be used."
|
||||||
:clj (.matcher ^SegmentTrie (or segment (SegmentTrie.)))))
|
#?(:cljs trie
|
||||||
|
:clj (.matcher ^SegmentTrie (or trie (SegmentTrie.)))))
|
||||||
|
|
||||||
(defn lookup [segment path]
|
(defn lookup [trie path]
|
||||||
#?(:cljs (if-let [match (-lookup segment (impl/segments path) {})]
|
"Looks the path from a Segment Trie. Returns a [[Match]] or `nil`."
|
||||||
|
#?(:cljs (if-let [match (-lookup trie (impl/segments path) {})]
|
||||||
(assoc match :path-params (impl/url-decode-coll (:path-params match))))
|
(assoc match :path-params (impl/url-decode-coll (:path-params match))))
|
||||||
:clj (if-let [match ^SegmentTrie$Match (SegmentTrie/lookup segment path)]
|
:clj (if-let [match ^SegmentTrie$Match (SegmentTrie/lookup trie path)]
|
||||||
(->Match (.data match) (clojure.lang.PersistentHashMap/create (.params match))))))
|
(->Match (.data match) (clojure.lang.PersistentHashMap/create (.params match))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue