MochiKit.DOM.isChildNode and isParent

6 views
Skip to first unread message

Per Cederberg

unread,
Oct 8, 2008, 9:51:16 AM10/8/08
to MochiKit
The two functions MochiKit.DOM.isChildNode and isParent have both been
added in version 1.4 of MochiKit (not yet stable). But they are
virtually identical (except for a few bugs I'm in fixing right now).
The only difference, according to the API docs, as far as I can tell
is:

isChildNode(node, node) --> true
isParent(node, node) --> false

Is it not pointless to keep both functions around? Since isChildNode()
is more tested (and probably more used), I'd suggest removing
isParent() from the API before the 1.4 release. Possibly, in order to
simplify the transition, we could just alias isParent to isChildNode
(and remove the API doc specification so that noone will use it from
now on).

Opinions?

Cheers,

/Per

PS. I just discovered that Google Groups silently dropped all my
emails that used another sender address, so I'm currently resending
all my recent postings. Hence the sudden email bombing...

Per Cederberg

unread,
Oct 17, 2008, 4:29:13 PM10/17/08
to MochiKit
Noone has opinions on this?

Cheers,

/Per

Jason Bunting

unread,
Oct 17, 2008, 6:23:40 PM10/17/08
to Per Cederberg, MochiKit
Who is Noone? :P

Personally, I agree that it seems pointless to have isParent around when
isChild will do the same thing. I don't even think the alias is needed, if
someone wanted the semantics that would provide, let them alias it
themselves, I say.

There is my opinion, for what little it is worth.

Jason Bunting

> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com
> Version: 8.0.173 / Virus Database: 270.8.1/1730 - Release Date: 10/17/2008
> 8:07 AM

Christoph Zwerschke

unread,
Oct 18, 2008, 11:54:46 AM10/18/08
to MochiKit
Hm, if I read the code correctly, then there is another difference,
namely that isChildNode also returns true if the second node is not the
direct parent, but also for grandparents and any ancestors. So it should
be actually renamed to something like isDescendant or isAncestor.

You can merge the functions by using an additional flag (e.g.
direct=true), but it's probably easier to have two separate functions.
However, they certainly need better names & documentation.

-- Christoph

Per Cederberg schrieb:

Per Cederberg

unread,
Oct 18, 2008, 12:42:21 PM10/18/08
to MochiKit
Attempting two answers in one below...

On Sat, Oct 18, 2008 at 12:23 AM, Jason Bunting
<thurber...@hotmail.com> wrote:
> Who is Noone? :P

Sigh... The endless joys we bring you native English speakers... ;-)

On Sat, Oct 18, 2008 at 5:54 PM, Christoph Zwerschke <ci...@online.de> wrote:
> Hm, if I read the code correctly, then there is another difference,
> namely that isChildNode also returns true if the second node is not the
> direct parent, but also for grandparents and any ancestors. So it should
> be actually renamed to something like isDescendant or isAncestor.

Both actually do that. But isParent() does it through recursion
instead of iteration:

isParent: function (child, element) {
var self = MochiKit.DOM;
if (typeof(child) == "string") {
child = self.getElement(child);
}
if (typeof(element) == "string") {
element = self.getElement(element);
}
if (child == null || element == null) {
return false;
} else if (!child.parentNode || child == element) {
return false;
} else if (child.parentNode == element) {
return true;
} else {
return self.isParent(child.parentNode, element);
}
},

I totally agree on the naming. Should be named as you propose, but I
don't see us changing the API right now though... :-(

Cheers,

/Per

Bob Ippolito

unread,
Oct 18, 2008, 12:58:08 PM10/18/08
to Per Cederberg, MochiKit
I don't see any direct references to either isParent or isChildNode in
any of our code here at Mochi, so I don't care ;)

-bob

Christoph Zwerschke

unread,
Oct 18, 2008, 3:04:21 PM10/18/08
to MochiKit
Per Cederberg wrote:
> Both actually do that.

Ah, right. Overlooked the recursive call in the last line of isParent.
Then both names are really misleading. It's completely unusual to call a
not direct ancestor "parent" or a not direct descendant "child".

And there's really no reason to keep them both, or making one the alias
of the other. If both functions are there, then they should have least
swapped arguments, like here:
http://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic=/com.ibm.dbext.doc/dbext270.htm

-- Christoph

Per Cederberg

unread,
Oct 19, 2008, 3:52:40 AM10/19/08
to MochiKit
Ok, since r1433 MochiKit.DOM.isParent is no more.

/Per

Reply all
Reply to author
Forward
0 new messages