1.4.2 • Published 3 months ago

@remote-ui/traversal v1.4.2

Weekly downloads
66
License
MIT
Repository
-
Last release
3 months ago

@remote-ui/traversal

This package provides a set of utility functions for finding components within a @remote-ui/core RemoteRoot.

Installation

Using yarn:

yarn add @remote-ui/traversal

or, using npm:

npm install @remote-ui/traversal --save

Usage

find()

Returns the nearest descendant RemoteComponent whose type matches the passed type.

import {createRemoteRoot} from '@remote-ui/core';
import {find} from '@remote-ui/traversal';

const root = createRemoteRoot(() => {});
const buttonGroup = root.createComponent('ButtonGroup');

buttonGroup.append(root.createComponent('Button'));
root.append(buttonGroup);

const button = find(root, 'Button');

You can optionally pass a props argument as the third parameter. This will find a matching component with a matching subset of props.

import {createRemoteRoot} from '@remote-ui/core';
import {find} from '@remote-ui/traversal';

const root = createRemoteRoot(() => {});
const buttonGroup = root.createComponent('ButtonGroup');
const buttonOne = root.createComponent('Button', {id: 'one'});

buttonGroup.append(buttonOne);
buttonGroup.append(root.createComponent('Button', {id: 'two'}));
root.append(buttonGroup);

const buttonTwo = find(root, 'Button', {id: 'two'});

findAll()

Like find(), but returns all matching components in an array.

closest()

Returns the component passed as the first argument, if it matches the type (and optional props) passed to this function, or returns the first matching ancestor that does match by traversing recursively through all parents.

import {createRemoteRoot} from '@remote-ui/core';
import {closest} from '@remote-ui/traversal';

const root = createRemoteRoot(() => {});
const buttonGroup = root.createComponent('ButtonGroup');
const button = root.createComponent('Button');

buttonGroup.append(button);
root.append(buttonGroup);

const foundButtonGroup = closest(button, 'ButtonGroup'); // same as buttonGroup
1.4.2

3 months ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.16

2 years ago

1.3.13

2 years ago

1.3.14

2 years ago

1.3.11

2 years ago

1.3.12

2 years ago

1.3.15

2 years ago

1.3.10

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.2.2

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.2.0-alpha.0

3 years ago

1.1.10

3 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago