bonzo icon indicating copy to clipboard operation
bonzo copied to clipboard

Is there any reason why the constructor function doesn't normalize its inputs?

Open aawwawa opened this issue 13 years ago • 6 comments

If it did, it would save a hell of a lot of bonzo.create()s.

Anyway, it came up in IRC, and I was wondering if anyone else might be able to provide insight. If there's no good reason not to, then I'd like to propose that normalization get added...

Cheers!

aawwawa avatar Nov 27 '12 16:11 aawwawa

can you give an example? there's probably a very good reason — if not simply for the sake of speed, and that doing this via Ender would do it anyway.

ded avatar Nov 27 '12 17:11 ded

@ded I was discussing this with @adlwalrus and I couldn't come with a good reason that bonzo() isn't more clever and wondered if there was something I was overlooking.

bonzo(bonzo.create('<p>')).appendTo('#something') // unnecessarily awkward

The manip methods are clever enough to normalize() & query(), the constructor should probably be too, for Bonzo stand-alone. There's already a typeof elements == 'string' check in there but it doesn't do anything sensible.

That, and the fact that bonzo.create() doesn't return a Bonzo collection.

rvagg avatar Nov 27 '12 21:11 rvagg

hmmm.... i suppose so... we'd have to bump up the package a minor version tho

ded avatar Nov 27 '12 23:11 ded

and update a few tests...

ded avatar Nov 27 '12 23:11 ded

Anyone wanna do it? If not, then anyone wanna coach me through doing it?

aawwawa avatar Nov 28 '12 02:11 aawwawa

Well that was silly... how does this look? https://github.com/ded/bonzo/pull/103

(I had a look over the tests to see if there were any I could clearly identify as needing to be updated, but it appears not.)

(Also, I'm still not sure what @rvagg was talking about with query() after poking around in the sources. I assume it has to do with being able to pass a selector into the constructor, but I'm not sure.)

aawwawa avatar Nov 28 '12 02:11 aawwawa