New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

synced-store

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

synced-store

A synced store based Y.js.

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

synced-store

A synced store based Y.js. More information see: API

Install

pnpm install synced-store

Usage

import { SyncedStorage, Storage } from "synced-store";

type ClassroomStorageState = {
    ban: boolean;
    raiseHandUsers: string[];
    shareScreen: boolean;
};

const roomUUID = "exampleRoom";

// replace to your own websocket server
const hostUrl = "ws://localhost:1234";

const syncedStorage = new SyncedStorage(roomUUID, hostUrl);
const classroomStorage: Storage<ClassroomStorageState> =
    syncedStorage.connectStorage<ClassroomStorageState>("classroom", {
        ban: false,
        raiseHandUsers: [],
        shareScreen: false,
    });

console.log(classroomStorage.state); // { ban: false, raiseHand: [] }

classroomStorage.setState({
    raiseHandUsers: ["user1", "user2"],
});

console.log(classroomStorage.state); // { ban: false, raiseHandUsers: [ 'user1', 'user2' ] }

// you can call disposer to remove listener or add it to your disposer manager
const disposer = classroomStorage.on("stateChanged", (diff: Partial<ClassroomStorageState>) => {
    console.log(diff); // the updated value
});

classroomStorage.resetState();

console.log(classroomStorage.state); // { ban: false, raiseHand: [] }

If you want to host in local, you can use y-websocket. More detail see this test

Usage in tldraw

import { useMemo } from "react";
import { TLRecord } from "@tldraw/tldraw";
import { TlDrawSyncedStorage } from "synced-store"

const roomUUID = "exampleRoom"
const hostUrl = "ws://localhost:1234" // replace to your host url

const { syncedStorage, room } = useMemo(() => {
    const syncedStorage = new TlDrawSyncedStorage<TLRecord>(
        roomUUID,
        { id: `tl_${roomUUID}` } as TLRecord,
        hostUrl,
    );

    return {
        syncedStorage,
        room: syncedStorage.provider,
    };
}, [hostUrl, roomUUID]);

License

MIT @Openflat

Keywords

synced-store

FAQs

Package last updated on 31 Jan 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