Skip to content

ipfs-shipyard/peer-crdt-bind-codemirror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

peer-crdt-bind-codemirror

Binds a Codemirror editor and peer-crdt.

Install

$ npm install peer-crdt-bind-codemirror

Example

const Codemirror = require('codemirror')
const bind = require('peer-crdt-bind-codemirror')
const crdt = ...
const cursorCrdt = ...
const editor = Codemirror.fromTextArea(document.getElementById('codemirror'))

// bind editor to an array CRDT
const unbind = bind.editor(crdt, editor)

// bind cursors to a register CRDT
const unbindCursors = bind.cursors(cursorCrdt, editor)

// some time later ...

unbind()
unbindCursors()

API

bind (crdt, editor [, options])

Returns an unbind function.

Arguments:

  • crdt: must be a CRDT of type treedoc
  • editor: an instance of Codemirror
  • options: optional object with the following shape:
    • debounceMS: how long (in miliseconds) after the last edit should the CRDT be updated. Default is 2000.

bind.cursors (crdt, editor)

Returns an unbind function.

Arguments:

  • ipfs: IPFS node
  • crdt: must be a CRDT of type mv-register
  • editor: an instance of Codemirror
  • options: optional object with the following shape:
    • debounceMS: how long (in miliseconds) after the cursor position changed should the CRDT be updated. Default is 2000.

See example.

License

MIT

About

peer-crdt binding for codemirror

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages