How to use the sharedb/lib/client/doc.prototype function in sharedb

To help you get started, we’ve selected a few sharedb 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 dmapper / react-sharedb / src / subscribe.js View on Github external
function bindMethods (object, methodsToBind) {
  for (let method of methodsToBind) {
    object[method] = object[method].bind(object)
  }
}

function getScopedModelName (key) {
  return `$${key}`
}

// ----------------------------------------------
//   Monkey patches of ShareDB and Racer
// ----------------------------------------------

// Patch applying sharedb operations to prevent extra rerender from triggering
const oldHandleOp = SharedbDoc.prototype._handleOp
SharedbDoc.prototype._handleOp = function () {
  let value
  batching.batch(() => {
    value = oldHandleOp.apply(this, arguments)
  })
  return value
}

const BATCH_SETTERS = ['_mutate', '_setEach', '_setDiff', '_setDiffDeep']

for (let methodName of BATCH_SETTERS) {
  const oldMethod = racer.Model.prototype[methodName]
  racer.Model.prototype[methodName] = function () {
    let value
    batching.batch(() => {
      value = oldMethod.apply(this, arguments)
github dmapper / react-sharedb / src / subscribe.js View on Github external
for (let method of methodsToBind) {
    object[method] = object[method].bind(object)
  }
}

function getScopedModelName (key) {
  return `$${key}`
}

// ----------------------------------------------
//   Monkey patches of ShareDB and Racer
// ----------------------------------------------

// Patch applying sharedb operations to prevent extra rerender from triggering
const oldHandleOp = SharedbDoc.prototype._handleOp
SharedbDoc.prototype._handleOp = function () {
  let value
  batching.batch(() => {
    value = oldHandleOp.apply(this, arguments)
  })
  return value
}

const BATCH_SETTERS = ['_mutate', '_setEach', '_setDiff', '_setDiffDeep']

for (let methodName of BATCH_SETTERS) {
  const oldMethod = racer.Model.prototype[methodName]
  racer.Model.prototype[methodName] = function () {
    let value
    batching.batch(() => {
      value = oldMethod.apply(this, arguments)
    })