Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Convert trieNode to ES6 class #71

Merged
merged 9 commits into from
Jan 15, 2019
Merged

Convert trieNode to ES6 class #71

merged 9 commits into from
Jan 15, 2019

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Jan 14, 2019

This PR converts TrieNode to an ES6 class and extracts hex prefix encoding functions to a different file, as hex prefix is an encoding method and is conceptually separate from a trie node (although encoding is used in the trie node class). It also transforms source files with babelify for karma tests.

If I'm not mistaken, hex prefix functions were not exposed and therefore this shouldn't be an API change.

Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
@coveralls
Copy link

coveralls commented Jan 14, 2019

Coverage Status

Coverage decreased (-0.5%) to 93.92% when pulling 8f7c593 on refactor/trie-node into 37272b7 on master.

Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
@s1na s1na requested a review from alextsg January 14, 2019 15:49
@holgerd77
Copy link
Member

Can we name this hex-prefix.js file differently - probably just util.js - since the name is not describing the range of functionality brought together there?

@holgerd77
Copy link
Member

Update: just saw that there was a file util.js before, still think it would be better to combine there (so: under that name). Or do you have got an alternative suggestion for a more fitting name?

@s1na
Copy link
Contributor Author

s1na commented Jan 15, 2019

@holgerd77 I agree the name is a bit confusing (can be confused with 0x hex prefix), but this is the name the yellow paper (appendix c) gives to this encoding method. The functions in hex-prefix.js are are related to encoding paths, decoding them, comparing them, etc.

I'll try to make this more clear during typescript transition by using types.

Update: I'll be happy to change the name if you have suggestions? (other than utils, I really dislike anything called utils 😄)

@holgerd77
Copy link
Member

One first-thought suggestion: we could add a directory util with three files execution.js (what has been left in util.js), hex.js (the two hex-functions) and nibbles.js (nibble-related functionality).

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, left some comments and there is this util naming stuff, generally looks good, thanks! The more I look into the code the more I think this is really needed.

@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "npm run test:node && npm run test:browser",
"coverage": "istanbul cover tape ./test/*.js",
"coverage": "istanbul cover babel-tape-runner ./test/*.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not understanding the intention respectively the effect of this change, could you describe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coverage tests were failing due to some ES6 syntax. Unit tests were already using babel-tape-runner ("test:node": "babel-tape-runner ./test/*.js",).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok.

export function doKeysMatch (keyA, keyB) {
var length = matchingNibbleLength(keyA, keyB)
return length === keyA.length && length === keyB.length
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to go through the whole library on this, but since we are aggregating here could you have at least for the functions included in this file have some look at the JSDoc API comments? These are very inconsistent with missing values and stuff.

this.setKey(key)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

}

/**
* Determines if a key has Arnold Schwarzenegger in it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this kind-of funny but this is nevertheless irritating and I already "stumbled" over this several times and it prevents getting what this really does. 😄 Could you replace with a proper description of the functionality provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yeah I had the same feeling when I saw this :)) Added a description.

} else {
key = key.slice(0) // copy the key
if (arguments.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phew, this kind of stuff is really very ugly and hard to read (was puzzled for some time regarding the function call forwardings of the respective get and set methods. We should keep it for now but also change this mid-term.

}

return 'extention'
return children
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've gone through the trieNode.js file function by function and compared, seems to look good.

Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants