How to use the sharedb.Backend.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 derbyjs / racer / lib / Backend.js View on Github external
var Backend = require('sharedb').Backend;
var Model = require('./Model');
var util = require('./util');

module.exports = RacerBackend;

function RacerBackend(racer, options) {
  Backend.call(this, options);
  this.racer = racer;
  this.modelOptions = options && options.modelOptions;
  this.on('bundle', function(browserify) {
    var racerPath = path.join(__dirname, 'index.js');
    browserify.require(racerPath, {expose: 'racer'});
  });
}
RacerBackend.prototype = Object.create(Backend.prototype);

RacerBackend.prototype.createModel = function(options, req) {
  if (this.modelOptions) {
    options = (options) ?
      util.mergeInto(options, this.modelOptions) :
      this.modelOptions;
  }
  var model = new Model(options);
  this.emit('model', model);
  model.createConnection(this, req);
  return model;
};

RacerBackend.prototype.modelMiddleware = function() {
  var backend = this;
  function modelMiddleware(req, res, next) {