![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@eidos/ui-kit
Advanced tools
The Handle Object system can be used to add "handle ID" attributes to the DOM so
that they can be identified in automated browser testing. The Handle Object
allows you to identify functionally important DOM elements in your tests using
an alternative structural semantic scheme of your choice, rather than e.g.
div > div > div > ul > li > div
.
interface MyComponentProps {
handle?: Handle;
}
function MyComponent(props: MyComponentProps) {
return <div {...props.handle} />;
}
Handle
prop.render(<MyComponent handle={createHandle()} />, document.getElementById("app"));
In the DOM, the div
or MyComponent
will receive a value for the
data-handle-id
attribute. Since our handle is simple, this attribute value
will be ""
, signifying the root handle. This obviously is of very
little practical use, so let us see how we can make something more useful by
creating structural handles.
Now we will create a handle with some structure inside it. Suppose our
application is made of a ComponentA
that internally has two instances of
ComponentB
.
function ComponentB() {
return <div>I'm B</div>;
}
function ComponentA() {
return (
<div>
I'm A, and I have two B's inside me:
<ComponentB />
<ComponentB />
</div>
);
}
Now we'll allow the wrapper div
of ComponentB
and that of ComponentA
be
identified with our handles. The Handle for ComponentB
will be just like what
we had with MyComponent
: a simple Handle
interface ComponentBProps {
handle?: Handle;
}
function ComponentB(props: ComponentBProps) {
return <div {...props.handle}>I'm B</div>;
}
For ComponentA
, however, we have a "structure": twice ComponentB
s. We can
define a type-parameterized Handled
to declare this fact.
interface ComponentAShape {
b1: {};
b2: {};
}
interface ComponentAProps {
handle?: Handle<ComponentAShape>;
}
function ComponentA(props: ComponentAProps) {
return (
<div {...props.handle}>
I'm A, and I have two B's inside me:
<ComponentB handle={props.handle?.b1} />
<ComponentB handle={props.handle?.b2} />
</div>
);
}
Now, when mounting ComponentA
as root, we will have the following elements
receiving data-handle-id
attributes:
ComponentA
will receive ""
(root handle)ComponentB
will receive "b1"
ComponentB
will receive "b2"
So now you can use something like the below to get back the DOM element in browser-based automated testing.
document.querySelector('[data-handle-id="b1"]');
Or better still, do it symbolically:
const rootHandle = createHandle<ComponentAShape>();
render(<MyComponent handle={rootHandle} />, document.getElementById("app"));
// ... Then later ...
document.querySelector(`[data-handle-id="${CSS.escape(rootHandle.b1)}"]`);
With Selenium Web Driver, you could do something like this (with aid of the css.escape module to allow CSS escaping in Node).
driver.findElement(By.css(CSS.escape(rootHandle.b1)));
Doing it symbolically is especially useful in TypeScript, as this plays well with IDEs such as VSCode offering to refactor-rename your handle shape interface properties: All names become traceable, you have single source of truth, and you can refactor with confidence!
Note that the use of Handle is not exclusive to React. Any componentized UI pattern can make use of it.
The Handle Object, created first by calling createHandle()
, is an ES6
proxy object with a few special properties that allow them to be used to
describe UI Element structures in a semantic that is aside from the literal DOM
element hierarchy.
const handle = createHandle(); // This is a handle
const foo = handle.foo; // This is also a handle
const bar = foo.bar; // This is also a handle
data-handle-id
property, or, more strictly, the
property encoded by the export HANDLE_ID_ATTRIBUTE
handle[HANDLE_ID_ATTRIBUTE]; // ""
foo[HANDLE_ID_ATTRIBUTE]; // "foo"
bar[HANDLE_ID_ATTRIBUTE]; // "foo:bar"
HANDLE_ID_ATTRIBUTE
will be iterated.const spreadFoo = { ...foo }; // { [HANDLE_ID_ATTRIBUTE]: "foo" }
createHandle
accepts an optional type parameter
describing the shape of the handle's structure; this can be used to limit
the set of "allowed" properties that can be materialized.const handle = createHandle<{ foo: {}; bar: { baz: {} } }>();
handle.foo; // OK
handle.bar; // OK
handle.baz; // Type Error, `baz` doesn't exist on `handle`.
handle.bar.baz; // OK
FAQs
Unknown package
The npm package @eidos/ui-kit receives a total of 0 weekly downloads. As such, @eidos/ui-kit popularity was classified as not popular.
We found that @eidos/ui-kit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.