Liking cljdoc? Tell your friends :D

paginate-vector

A Clojure implementation of the GraphQL Cursor Connections Specification with vector(s) as the backing data.

Supports:

  • Multiple vectors as input
  • Vectors that grows
  • Polling pagination

Installation

Clojars Project

1-minute example

(require '[com.github.ivarref.paginate-vector :as pv])

(def my-data [0 1 2])

(defn nodes [page]
  (->> page
       :edges
       (mapv :node)))


; Get the initial page:
(def page-1 (pv/paginate [my-data]
                          identity 
                          {:first 2}))
; (nodes page-1)
; => [0 1]

; Get the second page:
(def page-2 (pv/paginate [my-data]
                         identity
                         {:first 2
                          :after (get-in page-1 [:pageInfo :endCursor])}))
; (nodes page-2)
; => [2]

; Get the next (empty) page:
(def page-3 (pv/paginate [my-data]
                         identity
                         {:first 2
                          :after (get-in page-2 [:pageInfo :endCursor])}))
; (nodes page-3)
; => []
; No more data! 
; The poller should now sleep for some time before attempting again.

; Time for another poll.
(def page-4 (pv/paginate [[0 1 2 3 4]] ; More data has arrived
                         identity
                         {:first 2
                          :after (get-in page-3 [:pageInfo :endCursor])}))
; (nodes page-4)
; => [3 4]

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close