Giter Site home page Giter Site logo

mmamedel / svelt-yjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from relm-us/svelt-yjs

0.0 0.0 0.0 435 KB

A library for your Svelte app that lets you build Svelte stores from Yjs types.

License: MIT License

JavaScript 21.67% TypeScript 27.02% CSS 13.58% HTML 1.46% Svelte 36.28%

svelt-yjs's Introduction

Svelt-yjs

Svelt-yjs is a library for your Svelte app that lets you build Svelte stores from Yjs types. When built on the client-side Yjs library, your Svelte app gets transport-agnostic synchronization (e.g. y-webrtc, y-websocket ) across networks and undo/redo management basically for free.

Yjs is often thought of as a way to make collaborative text editing work in a browser, but its underlying technology is amenable to a variety of web use cases. We think Svelte and Yjs are positioned to make collaborative, local-first apps much easier to build.

At Relm, for example, we've been using it as the synchronization layer between participants in a collaborative 3D world.

Live Demo

See https://svelt-yjs.dev

Open it up in multiple browsers at the same time!

Note: the source code for the Live Demo is in the example/ folder.

Getting Started

Starting with a Svelte component:

<script lang="ts">
  import { readableArray } from 'svelt-yjs'
  import * as Y from 'yjs'

  // All Yjs types must be embedded in a Y.Doc
  const ydoc: Y.Doc = new Y.Doc()

  // Create a Y.Array in the Y.Doc
  const yarray: Y.Array<string> = ydoc.getArray('list')

  // Generate a Svelte readable store from the Y.Array
  const list = readableArray(yarray)

  // The store has a `y` object that references `yarray`
  // Note: The following is identical to `yarray.push(['one', 'two', 'three'])`
  //       See Yjs docs for other methods on Y.Array.
  list.y.push(['one', 'two', 'three'])
</script>

{#each $list as item, i}
  <div>
    {item}
    <button on:click={() => list.y.delete(i)}>remove</button>
  </div>
{/each}

License

MIT

svelt-yjs's People

Contributors

canadaduane avatar miaourt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.