Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kvnneff/deku-component-find-all
Traverse a component tree and return all components that satisfy a function.
https://github.com/kvnneff/deku-component-find-all
Last synced: 25 days ago
JSON representation
Traverse a component tree and return all components that satisfy a function.
- Host: GitHub
- URL: https://github.com/kvnneff/deku-component-find-all
- Owner: kvnneff
- License: mit
- Created: 2015-11-26T01:04:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-26T03:36:51.000Z (almost 9 years ago)
- Last Synced: 2024-09-18T06:30:21.749Z (about 2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deku - deku-component-find-class - Traverse a Deku component tree and return with a given class name. (Testing)
README
# deku-component-find-all [![Build Status](https://travis-ci.org/kvnneff/deku-component-find-all.svg?branch=master)](https://travis-ci.org/kvnneff/deku-component-find-all)
Traverse a [Deku](https://github.com/dekujs/deku) component tree and return all components that satisfy a function.
Inspired by [react-shallow-testutils](https://github.com/sheepsteak/react-shallow-testutils)
## Example
```js
import findAll from 'deku-component-find-all'
import element from 'virtual-element'
import Mock from 'component-mock'const Component = {
render: function () {
element('ul', [
element('li', 'Foo'),
element('li', 'Bar')
])
}
}const mock = Mock(component)
const node = mock.render()let listElement = findAll(node, (element) => {
return element.children.length === 2
})listElement = listElement[0]
console.log(listElement.type) //=> returns `ul`
const listItems = findAll(node, (element) => {
return element.type === 'li'
})console.log(listItems.length) //=> returns `2`
```## API
### findAll(node, fn)
Returns an array of items found within `node` that satisfy `fn`.
## License
MIT