-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add removeRecursive and listSubTreeBFS methods #88
Conversation
When it's ready to be reviewed, please squash your commit |
646d29d
to
ef4ba3f
Compare
It's ready for review, thanks! |
ef4ba3f
to
c89512c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left two notes
assert(typeof callback === 'function', 'callback must be a function.'); | ||
|
||
var self = this; | ||
var tree = [path]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes the path that was passed in as part of the results, which is also what ZKUtil.listSubTreeBFS
seems to do.
callback(error); | ||
return; | ||
} | ||
async.eachSeries(children.reverse(), function (nodePath, next) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse
is called here to remove leaf nodes first
Hey @alexguan, please review this when you get a chance |
When to merge |
Overall this is a good PR, however does it belong the core zookeeper client though? It's more like an util that should exist outside the client. |
index.js
Outdated
* @param [version=-1] {Number} The version of the node. | ||
* @param callback {Function} The callback function. | ||
*/ | ||
Client.prototype.removeAll = function(path, version, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the ZKUtil names better: removeRecursively
, which makes it clear that it will remove the provided root node as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's currently named deleteRecursive
(https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/ZKUtil.java#L51) but to keep the remove
naming convention of this library, should I change to removeRecursive
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to removeRecursive
and listSubTreeBFS
index.js
Outdated
* @param path {String} The node path. | ||
* @param callback {Function} The callback function. | ||
*/ | ||
Client.prototype.getAllChildren = function(path, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to expose this method? Again, the the listSubTreeBFS
is a better name even for private method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also a public method on ZKUtil. I'll rename this to listSubTreeBFS
.
It would be nice to have in this library so people don't have to implement or require a separate util to have this functionality. I see that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks, will merge and make a new release
Add methods
removeAll
andgetAllChildren
. Implementation is based off the javaZKUtil
class.Related issues: #54, #10