UNPKG

937 BJavaScriptView Raw
1import richText from 'rich-text'
2import Racer from 'racer'
3import RacerRemoteDoc from 'racer/lib/Model/RemoteDoc'
4import Query from 'racer/lib/Model/Query'
5import { promisifyAll } from 'bluebird'
6import batch from './batch'
7import ormPlugin from '@startupjs/orm'
8
9export default (ShareDB, { orm } = {}) => {
10 // Register rich-text type in ShareDB
11 ShareDB.types.register(richText.type)
12
13 // Mokney patch rich-text to properly work with racer
14 let oldRemoteDocOnOp = RacerRemoteDoc.prototype._onOp
15 RacerRemoteDoc.prototype._onOp = function () {
16 if (this.shareDoc.type === richText.type) return
17 return oldRemoteDocOnOp.apply(this, arguments)
18 }
19
20 // Promisify the default model methods like subscribe, fetch, set, push, etc.
21 promisifyAll(Racer.Model.prototype)
22 promisifyAll(Query.prototype)
23
24 // Add batching method
25 Racer.Model.prototype.batch = batch
26
27 if (orm) {
28 Racer.use(ormPlugin)
29 Racer.use(orm)
30 }
31}