Querying Virtual DOM elements using a css selector?
tusharmath opened this issue · comments
const vTree = h('div.landscape', [
h('div.saucer', {style: `transform:translate(${x}px, ${y}px)`})
])
// and then search as —
maquette.find(vTree, 'div.saucer')
Hello,
Querying a virtual DOM is normally only needed when doing unit testing. We created the project maquette-query
for this.
This project is still in pre-release and we welcome contributions. The selector may currently only contain one part (div
or .saucer
) in your example.
What is your use-case for querying?
I am building a DOM driver for cycle. The API looks as follow —
const click$ = DOM.select('.saucer').events('click')
Here click$
represents an Observable which emits the click event everytime the element is clicked upon.
I think it would be easier if you used the afterCreate
handler. This callback is meant to facilitate integration with other libraries. This function gets called with the DOM node that was created, so there is no need to find it using a query anymore. Good luck!
Its not documented here though — http://maquettejs.org/docs/typedoc/modules/_maquette_.html