UNPKG

706 BJavaScriptView Raw
1import richText from 'rich-text'
2import Racer from 'racer'
3import RacerRemoteDoc from 'racer/lib/Model/RemoteDoc'
4import batch from './batch'
5import ormPlugin from '@startupjs/orm'
6
7export default (ShareDB, { orm } = {}) => {
8 // Register rich-text type in ShareDB
9 ShareDB.types.register(richText.type)
10
11 // Mokney patch rich-text to properly work with racer
12 const oldRemoteDocOnOp = RacerRemoteDoc.prototype._onOp
13 RacerRemoteDoc.prototype._onOp = function () {
14 if (this.shareDoc.type === richText.type) return
15 return oldRemoteDocOnOp.apply(this, arguments)
16 }
17
18 // Add batching method
19 Racer.Model.prototype.batch = batch
20
21 if (orm) {
22 Racer.use(ormPlugin)
23 Racer.use(orm)
24 }
25}