How to use the yjs.extend function in yjs

To help you get started, we’ve selected a few yjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akshaykmr / oorja / app / imports / modules / Yjs / index.js View on Github external
import Y from 'yjs';

// types
import yArray from 'y-array';
import yMemory from 'y-memory';
import yMap from 'y-map';
import yText from 'y-text';
import yRichtext from 'y-richtext';
import yIndexDB from 'y-indexeddb';

import OorjaConnector from './OorjaConnector';

Y.extend(yArray, yMemory, yMap, yText, yRichtext, yIndexDB);
Y.extend('oorjaConnector', OorjaConnector);

export default Y;
github lukebarlow / y-plain-state / src / specs / specHelper / createUsers.js View on Github external
import YPlainState from '../../'

import Y from 'yjs'
import YMemory from 'y-memory'
import YTest from 'y-test'

Y.extend(YMemory, YTest, YPlainState)

async function createUsers (numberOfUsers) {
  if (Y.utils.globalRoom.users[0] != null) {
    await Y.utils.globalRoom.flushAll()
  }
  // destroy old users
  for (var u in Y.utils.globalRoom.users) {
    Y.utils.globalRoom.users[u].y.destroy()
  }
  var promises = []
  for (var i = 0; i < numberOfUsers; i++) {
    promises.push(Y({
      db: {
        name: 'memory',
        namespace: 'User ' + i,
        // cleanStart: true,
github akshaykmr / oorja / app / imports / modules / Yjs / index.js View on Github external
import Y from 'yjs';

// types
import yArray from 'y-array';
import yMemory from 'y-memory';
import yMap from 'y-map';
import yText from 'y-text';
import yRichtext from 'y-richtext';
import yIndexDB from 'y-indexeddb';

import OorjaConnector from './OorjaConnector';

Y.extend(yArray, yMemory, yMap, yText, yRichtext, yIndexDB);
Y.extend('oorjaConnector', OorjaConnector);

export default Y;
github citrusbyte / thicket / packages / thicket-webapp / src / database / index.js View on Github external
const ipfsConfig = {
  repo: 'thicket',
  EXPERIMENTAL: {
    pubsub: true,
  },
  config: {
    Addresses: {
      Swarm: [
        '/dns4/wrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star'
      ],
    },
  },
}

Y.extend(yIpfsConnector, yIndexeddb)
const persistence = new Y.IndexedDB()
const yConfig = (ipfs, id) => ({
  connector: {
    name: 'ipfs',
    room: `thicket:${id}`,
    ipfs,
    syncMethod: 'syncAll',
  },
})

const toBase64 = src =>
  `data:image/gif;base64,${btoa(new Uint8Array(src).reduce((data, byte) => data + String.fromCharCode(byte), ''))}`

// IPFS team has not yet implemented a timeout/cancel feature on fetching files
// if we try to fetch a file that is not in the reach of this node/peer this call will never finish/complete
// read more here
github FujitsuLaboratories / cattaz / server.js View on Github external
import 'regenerator-runtime/runtime';

/* eslint-disable no-console */

import Y from 'yjs';
import yWebsocketsServer from 'y-websockets-server';
import yMemory from 'y-memory';

import express from 'express';
import socketIo from 'socket.io';
import http from 'http';
import bodyParser from 'body-parser';
import clone from 'lodash/clone';
import crypto from 'crypto';

Y.extend(yWebsocketsServer, yMemory);

const isProduction = process.env.NODE_ENV === 'production';
const serverMode = process.env.SERVER_MODE;

const port = Number.parseInt(process.env.PORT || '8080', 10);
const app = express();
const server = http.createServer(app);
const io = socketIo.listen(server);
const bodyParserText = bodyParser.text();

const yInstances = {};
const metadata = {};

function getInstanceOfY(room) {
  if (yInstances[room] == null) {
    yInstances[room] = Y({
github spacecraft-repl / SpaceCraft / src / editor.js View on Github external
import io from 'socket.io-client'

const code = $('.codemirror-textarea')

const editor = CodeMirror.fromTextArea(code, {
  lineNumbers: true,
  theme: 'one-dark',
  tabSize: 2,
  mode: 'ruby',
  lineWrapping: true,
  // Prevent bug with Yjs syncing.
  // - disable auto-re-indenting on certain characters (eg: `end`).
  electricChars: false
})
Y.extend(yWebsocketsClient, yMemory, yArray, yText)

// @todo: Check if this is always a valid way to get url.
const url = window.location.href
const socket = io(url)

Y({
  db: {
    name: 'memory' // store the shared data in memory
  },
  connector: {
    name: 'websockets-client',
    room: 'spacecraft-repl', // instances connected to the same room share data
    socket,
    url
  },
  share: { // specify the shared content
github citrusbyte / thicket / packages / thicket-webapp / src / database / index.js View on Github external
metadataGet = community =>
    this.initCommunity(community)
			.then(y => y.share.metadata.get(community))
			.then(data => { return { id: community, ...data }})
			.then(this.metadataMap)

	metadataMap = (data = {}) => {
		const { id, title = id, ...rest } = data
		return { id, title, ...rest }
	}

  metadataPost = (community, data) =>
    this.initCommunity(community).then(y => y.share.metadata.set(community, data))
}

Y.extend(yMemory, yArray, yMap, yIpfsConnector, yIndexeddb)

class DBInterface extends EventEmitter {
  constructor() {
    super()
    this.db = new Database()
    this.db.on('update', () => this.emit('update'))
  }

  get publications() {
    return {
      post: this.db.publicationsPost,
      get: this.db.publicationsGet,
			getById: this.db.publicationsGetById,
    }
  }
github lukebarlow / y-plain-state / examples / jigsaw-react / index.js View on Github external
import YPlainState, { setDefaults } from '../../src/index'

import Y from 'yjs'
import YWebsocketsClient from 'y-websockets-client'
import YMemory from 'y-memory'

Y.extend(YWebsocketsClient, YMemory, YPlainState)

import React from 'react'
import { render } from 'react-dom'
import Jigsaw from './components/Jigsaw'

function draw (state) {
  var tracks = state.tracks
  render(
    ,
    document.getElementById('main')
  )
}

Y({
  db: {
    name: 'memory'
github lukebarlow / y-plain-state / examples / basic / index.js View on Github external
import YPlainState from '../../src/index'

import Y from 'yjs'
import YWebsocketsClient from 'y-websockets-client'
import YMemory from 'y-memory'

Y.extend(YWebsocketsClient, YMemory, YPlainState)

function draw (state) {
  var data = document.getElementById('data')
  data.innerHTML = JSON.stringify(state, null, 2)
}

Y({
  db: {
    name: 'memory'
  },
  connector: {
    name: 'websockets-client',
    room: 'y-plain-state-examples-basic'
  },
  share: { state: 'Map' }
}).then((y) => {
github lukebarlow / y-plain-state / examples / jigsaw / index.js View on Github external
import YPlainState, { setDefaults } from '../../src/index'

import Y from 'yjs'
import YWebsocketsClient from 'y-websockets-client'
import YMemory from 'y-memory'

Y.extend(YWebsocketsClient, YMemory, YPlainState)

import { select, mouse as d3Mouse } from 'd3-selection'
import { drag as d3Drag } from 'd3-drag'
import 'd3-transition'

Y({
  db: {
    name: 'memory'
  },
  connector: {
    name: 'websockets-client',
    room: 'y-plain-state-examples-jigsaw'
  },
  share: { state: 'Map' }
}).then((y) => {
  const state = Y.PlainState(y.share.state)