Liking cljdoc? Tell your friends :D

com.github.ivarref.clj-paginate


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
          node-id-attrs
          f
          opts
          &
          {:keys [context batch? sort-fn] :or {context {} batch? false}})

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.

node-id-attrs: Attributes that gives a unique identifier of a node. Should be a single keyword or a vector of keywords. This value represents what attributes the vector is sorted by, but does not contain information about descending or ascending order. Evaluating ((apply juxt node-id-attrs) node) must give a unique identifier for the node. This value will be stored in the cursor.

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.

: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.

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.

node-id-attrs: Attributes that gives a unique identifier of a node.
               Should be a single keyword or a vector of keywords.
               This value represents what attributes the vector is sorted by,
               but does not contain information about descending or ascending order.
               Evaluating `((apply juxt node-id-attrs) node)` must give a unique identifier for the node.
               This value will be stored in the cursor.

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.

: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.


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