Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@y-block/array

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@y-block/array

The `y-array` component is a custom web component built with Atomico and Yjs. It allows you to bind and observe a Yjs `Y.Array` in a reactive manner, rendering its items dynamically based on provided templates.

npmnpm
Version
1.0.1-beta.1
Version published
Weekly downloads
0
-100%
Maintainers
0
Weekly downloads
 
Created
Source

y-array

The y-array component is a custom web component built with Atomico and Yjs. It allows you to bind and observe a Yjs Y.Array in a reactive manner, rendering its items dynamically based on provided templates.

Properties

PropertyTypeDescription
arrayY.ArrayA Yjs Array instance to be observed and rendered.

Slots

PropertyTypeDescription
UnassignedChildNodeThe item template

Usage

Basic Example

If you have an array of strings like this:

doc.getArray('my-array').insert(0, ["Hello", "Array!"])

You can create a component like this:

<y-array array="doc.getArray('my-array')">
    <input $:placeholder="item" />
</y-array>

Nested Example

If you have an array of objects, you can create and use the y-array component like this:

doc.getArray('my-array').insert(0, [
    {firstName: "Hello", lastName:"Array!", style:{padding: "5px", margin: "5px"}},
    {firstName: "So", lastName:"Sweet!", style:{padding: "5px", margin: "5px"}}
])
<y-array array="doc.getArray('my-array')">
    <input $:placeholder="firstName" $:style="style" />
    <input $:placeholder="lastName"  $:style="style" />
</y-array>

Lazy Loading Example

The Lazy story demonstrates how to dynamically update the array over time. This example pushes a new item to the array every second.

<script>
    const lazyArray = doc.getArray('lazyArray')
    lazyArray.push([{ text: "Lazy loading..", idx: 1 }]);

    setInterval(() => {
        lazyArray.push([{ text: `item ${idx}`, idx: lazyArray.get(lazyArray.length - 1).idx + 1 }]);
    }, 1000)
</script>

<y-array array="doc.getArray('lazyArray')">
    <input $:placeholder="text"></input>
    <input $:placeholder="idx"></input>
</y-array>

FAQs

Package last updated on 01 Jul 2024

Did you know?

Socket

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.

Install

Related posts