JSON API events not getting called #118

Closed
HansPinckaers opened this Issue Aug 10, 2012 · 8 comments

4 participants

@HansPinckaers

Hi there,

I got this strange problem that the JSON API events don't work.

If I register for events like this:

doc.at("groceries").on 'insert', (position, data) ->
    console.log data

doc.on 'change', (op) -> 
    console.log op

When I insert a object like this:

doc.at("groceries").insert(0, grocerie)

Only the 'change' event gets called. And not the 'insert' event.

BTW I tried to run the tests but I get this error:

Running tests...

/Users/Hans/ShareJS/Cakefile:13
      if (err) throw err;
                     ^
Error: Command failed: 
/Users/Hans/ShareJS/tests.coffee:1
(function (exports, require, module, __filename, __dirname) { # This runs all 
                                                              ^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:437:25)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at /usr/local/lib/node/nodeunit/lib/nodeunit.js:75:37
    at _concat (/usr/local/lib/node/nodeunit/deps/async.js:508:13)
    at async.forEachSeries.iterate (/usr/local/lib/node/nodeunit/deps/async.js:118:13)
    at async.forEachSeries (/usr/local/lib/node/nodeunit/deps/async.js:134:9)

    at ChildProcess.exithandler (child_process.js:536:15)
    at ChildProcess.EventEmitter.emit (events.js:91:17)
    at maybeClose (child_process.js:634:16)
    at Process._handle.onexit (child_process.js:676:5)

Is this a known problem?

@wmertens

This is very odd. Are you sure your coffee-script is correctly installed? I just did a fresh clone, npm install and cake test and all tests passed, including the one that tests for the 'insert' event at https://github.com/josephg/ShareJS/blob/master/test/types/json-api.coffee#L68

Would you be able to reproduce your problem in a test case from a fresh clone?

@HansPinckaers

Sorry for my late response, was a week off.

The responsible test starts on line 92 (https://github.com/josephg/ShareJS/blob/master/test/types/json-api.coffee#L92)

When I change this line:

doc.emit 'remoteop', [{p:['list',0],li:4}], doc.get()

to this:

doc.at('list').insert 0, 4

Than the test fails.

@HansPinckaers

Ok, I'm kinda new to this code.

But shouldn't the client emit a 'remoteop' message when the op that it send is accepted? Or maybe the server should send a 'remoteop' message when he accepts a new op?

@wmertens

Hi Hans,

You get remoteop when another client successfully submits an op to the server. See https://github.com/josephg/ShareJS/wiki/Client-API

@HansPinckaers

Yeah, but I do not receive them when I log for them. I will look into it, maybe I'm wrong. But the JSON api events seem to rely on the remoteop event; when I send a remoteop after I receive the confirmation from the server that the op submitted succesful the api events seem to work.

@wmertens

Well to know what's going on I'd have to go through the message flow, I'll take a look but not this week, too busy :-(

@tedsuo

I believe this is now resolved.

@josephg
ShareJS member

Great. It should at any rate be part of issue #239

@josephg josephg closed this Sep 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment