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

@y-block/map

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@y-block/map

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

latest
npmnpm
Version
1.0.1-beta.1
Version published
Maintainers
0
Created
Source

y-map

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

Properties

PropertyTypeDescription
mapY.MapA Yjs Map instance to be observed and rendered.

Slots

PropertyTypeDescription
UnassignedChildNodeGeneral content

Usage

Basic Example

The following example demonstrates a basic usage of the y-map component with static key-value pairs.

<y-map map={ymap({key1: "value1", key2: "value2"})}>
    <input $:value="key1"></input>
    <input $:value="key2"></input>
</y-map>

Complex Example

This example shows how to use the y-map component with nested y-array components to handle more complex data structures.

for example, the following code snippet demonstrates how to use the y-map component with a nested y-array component to handle a list of users.

Map setup:

const map = new Y.Doc().getMap("map");
map.set("users", new Y.Array([
    {name: "John Doe", age: 30},
    {name: "Jane Doe", age: 25}
])); 
<y-map map="map">
    <y-array $:array="users">
        <input $:value="name"></input>
        <input $:value="age"></input>
    </y-array>
</y-map>

Lazy Loading Example

The LazyMap story demonstrates how to dynamically update the map over time. This example updates the idx property of the map every second.

<script>
    const lazyMap = new Y.Doc().getMap("lazyMap");
    lazyMap.set("idx", 0);
    setInterval(() => {
        lazyMap.set("idx", lazyMap.get("idx") + 1);
    }, 1000);
</script>

<y-map map="lazyMap">
    <input $:value="idx" type="number"></input>
</y-map>

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