An xpath is basically a convenient and compositional way to define a filter function on nodes in a virtual DOM tree, resp. the React test renderer tree, roughly based on a 'path' through the tree.
The functions select
, select-all
, select-one
and contains?
apply that filter, starting from a specific
context node.
For example:
(require [reacl2.test-util.xpath :as xp :include-macros true])
(>> / ** "div" [xp/text (xp/is= "Hello")])
matches on all div
elements anywhere below the context node, that have a text content equal to "Hello"
.
(>> / my-class / "span" [:id (xp/is= "foo")])
matches on all span
children of instances of the class my-class
below the context node, that have the id "foo"
.
(>> my-class [xp/args (xp/is? = [42])])
matches the context node, if it is an instance of my-class
and if its argument vector equals [42]
.
(>> / "span" [xp/first])
matches the first span element below the context node.
An xpath is basically a convenient and compositional way to define a filter function on nodes in a virtual DOM tree, resp. the React test renderer tree, roughly based on a 'path' through the tree. The functions [[select]], [[select-all]], [[select-one]] and [[contains?]] apply that filter, starting from a specific _context node_. For example: ``` (require [reacl2.test-util.xpath :as xp :include-macros true]) (>> / ** "div" [xp/text (xp/is= "Hello")]) ``` matches on all `div` elements anywhere below the context node, that have a text content equal to `"Hello"`. ``` (>> / my-class / "span" [:id (xp/is= "foo")]) ``` matches on all `span` children of instances of the class `my-class` below the context node, that have the id `"foo"`. ``` (>> my-class [xp/args (xp/is? = [42])]) ``` matches the context node, if it is an instance of `my-class` and if its argument vector equals `[42]`. ``` (>> / "span" [xp/first]) ``` matches the first span element below the context node.
(>> & forms)
Compose the given xpath selector forms to a combined selector, where from left to right, the selectors restrict the selection further. Special selector forms are:
/
selects the the immediate children.
.
selects/keeps the current node (will only rarely be needed).
..
selects the parent node.
...
selects the root node.
**
selects the current node and all its children and grand children.
[x y]
filters as with (where (>> x y))
Any other form should evaluate to a selector as with comp
.
For example (>> / **)
selects the children and all grand children from the current node.
Compose the given xpath selector forms to a combined selector, where from left to right, the selectors restrict the selection further. Special selector forms are: - `/` selects the the immediate children. - `.` selects/keeps the current node (will only rarely be needed). - `..` selects the parent node. - `...` selects the root node. - `**` selects the current node and all its children and grand children. - `[x y]` filters as with `(where (>> x y))` Any other form should evaluate to a selector as with [[comp]]. For example `(>> / **)` selects the children and all grand children from the current node.
Selects the current node and all of its children and
grand children. When using the composition macro >>
, the literal
**
is translated into this.
Selects the current node and all of its children and grand children. When using the composition macro [[>>]], the literal `**` is translated into this.
(and & selectors)
Selects the nodes that all of the given selectors selects.
Selects the nodes that all of the given selectors selects.
Selects the app-state if the current node is a Reacl component that has one.
Selects the app-state if the current node is a Reacl component that has one.
Selects the argument vector if the current node is a Reacl component.
Selects the argument vector if the current node is a Reacl component.
(attr name)
Selects the value of an attribute name
from virtual dom nodes. As a convience, a simple keyword k
is translated into (attr k)
.
Selects the value of an attribute `name` from virtual dom nodes. As a convience, a simple keyword `k` is translated into `(attr k)`.
Selects the children of the current node. When using the
composition macro >>
, the literal /
is translated into this.
Selects the children of the current node. When using the composition macro [[>>]], the literal `/` is translated into this.
(class c)
Selects only those nodes that are an instance of the given Reacl or React class c
.
Selects only those nodes that are an instance of the given Reacl or React class `c`.
Selects only those nodes that are a virtual component of any class type.
Selects only those nodes that are a virtual component of any class type.
(comp & selectors)
Compose the given xpath selector forms to a combined selector, where from left to right, the selectors restrict the filter further.
Valid selectors are all the primitives from this module, as well as:
tag
,attr
,class
Also see >>
for a convenience macro version of this.
Compose the given xpath selector forms to a combined selector, where from left to right, the selectors restrict the filter further. Valid selectors are all the primitives from this module, as well as: - strings stand for a virtual dom node as with [[tag]], - keywords stand for attribute names as with [[attr]], - Reacl classes stand for a selection by that class as with [[class]] Also see [[>>]] for a convenience macro version of this.
(contains? node selector)
Returns if the given selector
selects anything in the given node
, i.e. if the result of select-all
would be not-empty.
Returns if the given `selector` selects anything in the given `node`, i.e. if the result of [[select-all]] would be not-empty.
(count= n)
Keeps the current selection, if it contains the given number of nodes.
Keeps the current selection, if it contains the given number of nodes.
(css-class? s)
Keeps the current node only if it has a :class
attribute
matching with the given s
. If s
is a string or sequence, then
the node must have all those classes in the same order. If s
is a
set of strings, then it must have all those classes in any order.
Keeps the current node only if it has a `:class` attribute matching with the given `s`. If `s` is a string or sequence, then the node must have all those classes in the same order. If `s` is a set of strings, then it must have all those classes in any order.
Select nodes that are the first child of their parent.
Select nodes that are the first child of their parent.
(first-where sel)
Selects those nodes that are selected by the given selector, and for those that are not, the children are tried recursively.
Selects those nodes that are selected by the given selector, and for those that are not, the children are tried recursively.
(id= v)
Keeps the current node only if it has an attribute id
equal to v
.
Keeps the current node only if it has an attribute `id` equal to `v`.
(is= v)
Keeps the current node only if it is equal to v
.
Keeps the current node only if it is equal to `v`.
(is? pred & args)
Keeps the current node only if (pred node & args)
holds.
Keeps the current node only if `(pred node & args)` holds.
Selects the key property of the nodes, if they have one.
Selects the key property of the nodes, if they have one.
Select nodes that are the last child of their parent.
Select nodes that are the last child of their parent.
Selects the local-state if the current node is a Reacl component.
Selects the local-state if the current node is a Reacl component.
(not sel)
Selects those nodes that are not selected by the given selectors.
Selects those nodes that are not selected by the given selectors.
(nth n)
Select nodes that are the nth child, starting at index 0.
Select nodes that are the nth child, starting at index 0.
(nth-last n)
Select nodes that are the "nth but last" child.
Select nodes that are the "nth but last" child.
(or & selectors)
Selects the nodes that any of the given selectors selects.
Selects the nodes that any of the given selectors selects.
Selects the parent of the current node. When using the
composition macro >>
, the literal ..
is translated into this.
Selects the parent of the current node. When using the composition macro [[>>]], the literal `..` is translated into this.
(range from to)
Selects nodes based on their position in the children list of their
parent, starting at index from
(inclusive) up to index
to
(exclusive). Both from
and to
can be negative meaning a
position from the end of the children list. A 0 in from
means the
start of the list, but a 0 in to
stands for the end of list,
resp. one behind. So (range 0 0)
selects the full list of
children, (range 1 -1)
selects all but the first and the
last and (range -1 0)
only the last child.
Selects nodes based on their position in the children list of their parent, starting at index `from` (inclusive) up to index `to` (exclusive). Both `from` and `to` can be negative meaning a position from the end of the children list. A 0 in `from` means the start of the list, but a 0 in `to` stands for the end of list, resp. one behind. So `(range 0 0)` selects the full list of children, `(range 1 -1)` selects all but the first and the last and `(range -1 0)` only the last child.
(re-matches? regex)
Keeps the current node only if it is matches the given regex
.
Keeps the current node only if it is matches the given `regex`.
Select the root of the node tree. When using the composition macro >>
, the literal ...
is translated into this.
Select the root of the node tree. When using the composition macro [[>>]], the literal `...` is translated into this.
(select node selector)
Returns the node selected by selector
in the given node
, or throws if there is more than one, or returns nil
otherwise.
Returns the node selected by `selector` in the given `node`, or throws if there is more than one, or returns `nil` otherwise.
(select-all node selector)
Returns all nodes selected by selector
in the given node
.
Returns all nodes selected by `selector` in the given `node`.
(select-one node selector)
Returns the node selected by selector
in the given node
, or throws if there is none or more than one.
Returns the node selected by `selector` in the given `node`, or throws if there is none or more than one.
Selects the current node. This the identity element of composing selects with comp
.
Selects the current node. This the identity element of composing selects with [[comp]].
(style? style)
Keeps the current node only if it has a :style
attribute, which matches with all styles given in the map style
. Note
that it's ok if it has more styles.
Keeps the current node only if it has a `:style` attribute, which matches with all styles given in the map `style`. Note that it's ok if it has more styles.
(tag type)
Selects only those nodes that are a virtual dom element of the given string type
.
Selects only those nodes that are a virtual dom element of the given string `type`.
Selects only those nodes that are a virtual dom element of any tag type.
Selects only those nodes that are a virtual dom element of any tag type.
Selects the child nodes of type 'text'.
Selects the child nodes of type 'text'.
(text= s)
Selects the nodes where the text content is equal to the given string.
Selects the nodes where the text content is equal to the given string.
(type t)
Selects those nodes that either of the given dom tag type, or the given Reacl or React class.
Selects those nodes that either of the given dom tag type, or the given Reacl or React class.
A selector that drops everything, making a selection empty.
A selector that drops everything, making a selection empty.
(where sel)
Selects the nodes for which the given selector would result in a
non-empty list of nodes. When using the composition macro >>
, a
vector literal is translated into this.
Selects the nodes for which the given selector would result in a non-empty list of nodes. When using the composition macro [[>>]], a vector literal is translated into this.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close