josephg / josephg/ShareJS

JSON API 'child op' events called for incorrect paths

Open
#93 2 comments 0 reactions 0 assignees View on GitHub
bug discuss
Dominant language
JavaScript
Stars
5k
Forks
454
PR merge metrics
No merged PRs in 30d

Description

If my understanding of the 'child op' event listeners in the JSON API is correct then the events should only be called if the operation is performed on an ancestor of the path where the listener is attached.

This doesn't seem to be the case, the following two tests both fail as the event on ['foo', 'children', 0] is fired.

``` coffeescript
'child op sent to sibling': (test) ->
doc = new Doc {
foo: {
children: [{
key: 'value1'
}, {
key: 'value2'
}]
}
}

doc.at(['foo', 'children', 0]).on 'child op', (p, op) ->
# shouldn't call this event
assert.ok false

doc.at(['foo', 'children', 1]).on 'child op', (p, op) ->
assert.deepEqual p, 'key'
test.done()

doc.emit 'remoteop', [{p:['foo','children', 1, 'key'], od: 'value2', oi: 'newvalue2'}]

'child op sent to other nodes': (test) ->
doc = new Doc {
foo: {
children: [{
key: 'value1'
}, {
key: 'value2'
grandchild: {
key: 'value3'
}
}]
}
}

doc.at(['foo', 'children', 0]).on 'child op', (p, op) ->
# shouldn't call this event
assert.ok false

doc.at(['foo', 'children', 1]).on 'child op', (p, op) ->
assert.deepEqual p, ['grandchild', 'key']
test.done()

doc.emit 'remoteop', [{p:['foo','children', 1, 'grandchild', 'key'], od: 'value3', oi: 'newvalue2'}]
```

I believe this is related the behaviour of json.commonPath see issue #92

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.