josephg / josephg/ShareJS

json.commonPath not working as expected

Open
#92 3 comments 0 reactions 0 assignees View on GitHub
bug implement me
Dominant language
JavaScript
Stars
5k
Forks
454
PR merge metrics
No merged PRs in 30d

Description

I'm running into some issues with the json api, I was having some trouble getting the 'child op' events to work correctly as the path that was passed in seemed to be wrong. That led me to json.commonPath:

Adding these tests to test/types/json.coffee

``` coffeescript
'commonPath - all but last': (test) ->
test.deepEqual 1, type.commonPath ['children', 0], ['children', 1]
test.done()

'commonPath - all match': (test) ->
test.deepEqual 3, type.commonPath ['children', 0, 'value'], ['children', 0, 'value']
test.done()

'commonPath - none match': (test) ->
test.deepEqual 0, type.commonPath ['key1', 0, 'value'], ['key2', 1, 'value']
test.done()

'commonPath - different': (test) ->
test.deepEqual 1, type.commonPath ['children', 0, 'value'], ['children', 1, 'value']
test.done()

'commonPath - different lengths': (test) ->
test.deepEqual 1, type.commonPath ['children'], ['children', 1, 'value']
test.deepEqual 1, type.commonPath ['children', 1, 'value'], ['children']
test.done()
```

Seems to show that commonPath isn't correctly returning the actual length of the common path, which is what it appears to be trying to do.

I've fixed this function but it breaks a lot of the other tests because transformComponent uses commonPath and seems to rely on it's current behaviour, so before I dive into transformComponent I want to check and see if I'm on the right track or if commonPath is behaving as expected.

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.