Public docs for reitit.segment

This commit is contained in:
Tommi Reiman 2019-01-14 16:38:45 +02:00
parent 6bd005acbb
commit 75065b56e3

View file

@ -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))))))