Liking cljdoc? Tell your friends :D

com.github.ivarref.clj-paginate


compare-fnclj

(compare-fn sort-attrs)

Takes a vector of pairs as input. For example: [[:id :asc] [:date :desc]].

It also accepts a single keyword as input. This will be transformed to [[:keyword :asc]].

It also accepts a vector of keywords as input. This will be transformed to [[:kw1 :asc] [:kw2 :asc]].

Returns a function that can be used to sort a collection, e.g: (into [] (sort (compare-fn [[:id :asc] [:date :desc]]) my-vector))

Takes a vector of pairs as input.
For example: `[[:id :asc] [:date :desc]]`.

It also accepts a single keyword as input. This will be transformed to [[:keyword :asc]].

It also accepts a vector of keywords as input. This will be transformed to [[:kw1 :asc] [:kw2 :asc]].

Returns a function that can be used to sort a collection, e.g:
`(into [] (sort (compare-fn [[:id :asc] [:date :desc]]) my-vector))`
sourceraw docstring

ensure-orderclj

(ensure-order src-vec dst-vec & {:keys [sf df] :or {sf :id df :id}})

Orders dst-vec according to src-vec.

Optional named parameters sf anddfthat defaults to:id`.

(sf source-node) must be equal to some (df dest-node) for one element in dst-vec.

Orders dst-vec according to src-vec.

Optional named parameters `sf and `df`
that defaults to `:id`.

(sf source-node) must be equal to some
(df dest-node) for one element in dst-vec.
sourceraw docstring

get-contextclj

(get-context opts)

Gets the :context from a previous invocation of paginate as stored in :before or :after

Gets the :context from a previous invocation of paginate as stored in :before or :after
sourceraw docstring

paginateclj

(paginate data
          sort-attrs
          f
          opts
          &
          {:keys [context batch? sort-fn inclusive? sort?]
           :or {context {} batch? false inclusive? false sort? true}})

Required parameters

data: The data to paginate. Must be either a vector or a map with vectors as values. All vectors must be sorted based on node-id-attrs or :sort-fn. The actual nodes in the vectors must be maps.

sort-attrs: Attributes that specifies how the vector is sorted. It can be: * a single keyword. clj-paginate will assume ascending sorting. * a vector of keywords. clj-paginate will assume ascending sorting. * a vector of pairs. A pair must contain the keyword and :asc or :desc. Example: [[:id :asc] [:date :desc]].

f: Invoked on each node. Invoked a single time on all nodes if :batch? is true.

opts: A map specifying what data is to be fetched. It must contain either: :first: an int specifying how many nodes to fetch, starting at the beginning of the data.

  Or:
  :last: an int specifying how many nodes to fetch,
  starting at the end of the data.

  The cursor, i.e. where to continue fetching data from
  on subsequent queries, should be given as a string
  in :after if :first is used, or :before if :last is used.

  Opts may also contain `:filter`, which, if present, should be a collection of
  keys to filter the data map on. The filter value will be persisted in
  the cursor string, and will automatically be used on subsequent queries.
  If `:filter` is not specified, no filtering is done.
  Thus the default behaviour is to include everything.

Optional named parameters

:sort-fn: Supply a custom sorting function for how the data was sorted. This allows the data to be sorted descending based on some attribute, e.g. you may pass (juxt (comp - :foo) :bar) for :sort-fn while :node-id-attrs is given as [:foo :bar]. Defaults to (apply juxt node-id-attrs), i.e. ascending sorting for all attributes. Deprecated in favor of using sort-attrs e.g. [[:foo :desc] [:bar :asc]].

:context: User-defined data to store in every cursor. Must be pr-str-able. Defaults to {}. Can be retrieved on subsequent queries using (get-context ...).

:batch?: Set to true if f should be invoked a single time on all nodes, and not once for each node. If this is set to true, f must return the output nodes in the same order as the input nodes. Please see the ensure-order function for a helper function that makes sure the ordering is correct. The default value of :batch? is false.

:inclusive?: Set to true if the result should include the node pointed to by the cursor. This is useful if you want to check for updates to a given page only based on a previous pageInfo. The default value of :inclusive? is false.

:sort?: Set to false if you do not want clj-paginate to sort the vector(s) before doing anything. If set to false this will speed up processing, but of course requires that the data is already sorted. Defaults to true.

Return value

The paginated data. Returns a map of {:edges [{:node { ...} :cursor ...} {:node { ...} :cursor ...} ...] :pageInfo {:hasNextPage Boolean :hasPrevPage Boolean :totalCount Integer :startCursor String :endCursor String}}

Required parameters
====================
data: The data to paginate. Must be either a vector or a map with vectors as values.
      All vectors must be sorted based on `node-id-attrs` or `:sort-fn`.
      The actual nodes in the vectors must be maps.

sort-attrs: Attributes that specifies how the vector is sorted.
            It can be:
            * a single keyword. clj-paginate will assume ascending sorting.
            * a vector of keywords. clj-paginate will assume ascending sorting.
            * a vector of pairs. A pair must contain the keyword and :asc or :desc.
              Example: [[:id :asc] [:date :desc]].

f: Invoked on each node.
   Invoked a single time on all nodes if :batch? is true.

opts: A map specifying what data is to be fetched.
      It must contain either:
      :first: an int specifying how many nodes to fetch,
      starting at the beginning of the data.

      Or:
      :last: an int specifying how many nodes to fetch,
      starting at the end of the data.

      The cursor, i.e. where to continue fetching data from
      on subsequent queries, should be given as a string
      in :after if :first is used, or :before if :last is used.

      Opts may also contain `:filter`, which, if present, should be a collection of
      keys to filter the data map on. The filter value will be persisted in
      the cursor string, and will automatically be used on subsequent queries.
      If `:filter` is not specified, no filtering is done.
      Thus the default behaviour is to include everything.


Optional named parameters
=========================
:sort-fn: Supply a custom sorting function for how the data was sorted.
          This allows the data to be sorted descending based on some attribute,
          e.g. you may pass `(juxt (comp - :foo) :bar)` for `:sort-fn`
          while `:node-id-attrs` is given as `[:foo :bar]`.
          Defaults to `(apply juxt node-id-attrs)`, i.e. ascending sorting
          for all attributes.
          Deprecated in favor of using `sort-attrs` e.g. [[:foo :desc] [:bar :asc]].

:context: User-defined data to store in every cursor. Must be pr-str-able.
          Defaults to {}. Can be retrieved on subsequent queries using
          `(get-context ...)`.

:batch?: Set to true if f should be invoked a single time on all nodes,
         and not once for each node. If this is set to true,
         f must return the output nodes in the same order as the input nodes.
         Please see the `ensure-order` function for a helper function
         that makes sure the ordering is correct.
         The default value of :batch? is false.

:inclusive?: Set to true if the result should include the node pointed to by the cursor.
             This is useful if you want to check for updates to a given page only based on
             a previous pageInfo.
             The default value of :inclusive? is false.

:sort?: Set to `false` if you do not want clj-paginate to sort the vector(s) before doing anything.
        If set to `false` this will speed up processing, but of course requires that the data
        is already sorted.
        Defaults to `true`.

Return value
============
The paginated data.
Returns a map of
  {:edges [{:node { ...} :cursor ...}
           {:node { ...} :cursor ...}
            ...]
   :pageInfo {:hasNextPage Boolean
              :hasPrevPage Boolean
              :totalCount Integer
              :startCursor String
              :endCursor String}}
sourceraw docstring

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

× close