![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.
hotwire-virtualized
Advanced tools
Virtualized lists for Hotwire using Stimulus and Turbo Streams.
A minimal example within a Rails app can be found here.
<div
data-controller="virtualized"
data-virtualized-row-height-value="50"
data-virtualized-url-value="/load-items"
data-virtualized-ids-value="[1,2,3,4,5]"
style="height: 100vh"
>
<template data-virtualized-target="placeholder">
<li>Loading...</li>
</template>
<ul data-virtualized-target="content"></ul>
</div>
This library uses custom actions to interact with the virtualized list.
<turbo-stream action="v-replace" target="1">
<template>
<li>ID {id}</li>
</template>
</turbo-stream>
<turbo-stream action="v-remove" target="1"></turbo-stream>
<turbo-stream action="v-append" target="6">
<template>
<li>ID 6</li>
</template>
</turbo-stream>
<button
data-action="virtualized#actionRender"
data-virtualized-id-param="123"
data-virtualized-action-param="prepend"
>
Prepend ID
</button>
<button
data-action="virtualized#actionRender"
data-virtualized-id-param="123"
data-virtualized-action-param="append"
>
Append ID
</button>
Within a controller in your app, dispatch an event which includes:
prepend
, append
, remove
, before
, after
, replace
.id
.const { id, element } = this.buildElement();
this.dispatch("emit", {
detail: { id, element, action: "append", scrollTo: true },
});
Catch the event and forward it to the virtualized controller's eventRender
action:
<div
data-controller="event"
data-action="event:emit->virtualized#eventRender"
></div>
The actionRender
action can be called to prepend, append, insert, remove, etc... rows.
Require params:
document.querySelector(selector)
By default, the virtualized controller will fetch data from the backend for any IDs that aren't in its row cache. You can preload data into the row cache using the preloaded
target. This is useful when you want to render the first set of rows immediately.
You must pass a data attribute of data-preloaded-id="1"
where 1 is the ID that corresponds to the row, as it is how we correspond this row to the data in the row cache.
<template data-virtualized-target="preloaded" data-preloaded-id="1">
<li>Preloaded 1</li>
</template>
<template data-virtualized-target="preloaded" data-preloaded-id="2">
<li>Preloaded 2</li>
</template>
When you require multiple instances on a single page, you must set the virtualized-id
value to a unique value for each instance. The default value when not set is virtualized
.
<div
data-controller="virtualized"
data-virtualized-virtualized-id-value="virtual-a"
>
<!-- First Instance -->
</div>
<div
data-controller="virtualized"
data-virtualized-virtualized-id-value="virtual-b"
>
<!-- Second Instance -->
</div>
When stream responses need to target a specific instance must include the virtualized-id
attribute:
<turbo-stream action="v-replace" target="1" virtualized-id="virtual-a">
<template>
<li>Content</li>
</template>
</turbo-stream>
Events can also be targeted towards a specific instance using the virtualizedId
detail value:
this.dispatch("emit", {
detail: { id, element, action: "prepend", virtualizedId: "virtual-a" },
});
Requests to load data from the server will include the X-Virtualized-Id
header value in order to differentiate requests being made by different instances.
You can call the scrollTop
or scrollBottom
actions to scroll to the top or bottom of the list.
<button data-action="virtualized#scrollTop">Scroll Top</button>
<button data-action="virtualized#scrollBottom">Scroll Bottom</button>
FAQs
Virtualized lists for Hotwire
The npm package hotwire-virtualized receives a total of 2 weekly downloads. As such, hotwire-virtualized popularity was classified as not popular.
We found that hotwire-virtualized demonstrated a healthy version release cadence and project activity because the last version was released less than 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.