Skip to content

Commit

Permalink
Add hook: sync:edit(docId:String, edit:gulf.Edit)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelklehr committed Jun 14, 2016
1 parent b7bb38a commit c08474a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion components/sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
"use strict";
var gulf = require('gulf')
, WaterlineAdapter = require('./lib/waterline-adapter')
, co = require('co')

module.exports = setup
module.exports.consumes = ['orm', 'ot', 'queue', 'broadcast']
module.exports.consumes = ['orm', 'ot', 'queue', 'broadcast', 'hooks']
module.exports.provides = ['sync']

function setup(plugin, imports, register) {
var orm = imports.orm
, ot = imports.ot
, queue = imports.queue
, broadcast = imports.broadcast
, hooks = imports.hooks

var sync = {
documents: {}
Expand Down Expand Up @@ -74,6 +76,11 @@ function setup(plugin, imports, register) {
// send edits to other workers
doc.on('edit', function(edit) {
b.write(edit.pack())
co(function*() {
yield hooks.callHook('sync:edit', docId, edit)
})
.then(()=>{})
.catch((er) => console.error(er))
})
// listen to, apply and distribute edits of other workers
b.on('readable', function() {
Expand Down

0 comments on commit c08474a

Please sign in to comment.