-----
NOTE: Continued from an off-topic conversation that took place within
this thread:
http://groups.google.com/group/knockoutjs/browse_thread/thread/4b637817193799fb
- relevant details are included here, however, and I would love to
hear from others about this topic.
-----
On Jun 23, 6:02 pm, Mark Bradley <
barkmad...@gmail.com> wrote:
>
> On Fri, Jun 24, 2011 at 1:46 AM, JasonBunting <
jason.bunt...@gmail.com> wrote:
>
> > Off-topic, I would like to see all of the jQuery-aware code (hopefully
> > it's not aware of others as well, e.g. Dojo) removed from the core of
> > Knockout and moved into, perhaps, a compatibility file. Ditto on the
> > templating, if possible. The more this thing can be cut down the
> > better, right? Tell me I'm smoking crack if any of this sounds
> > crazy... If not, I may even be willing to help work on these things,
> > if needed. I just don't see why it can't be broken out a bit better to
> > make it as lean as possible.
>
> From what I understand of the code base, the only thing requiring
> knockout to use jquery (all the jquery specific code is protected by
> checks for its existence) is the template binding which you don't have
> to use (I also believe someone attempted to get knockout working with
> mustache earlier in the year).
>
> --
> -barkmadley
> sent from an internet enabled device
Partially, it's those checks I am referring to, though there is more -
including the template binding "which [no one has] to use."
I realize I am nitpicking (but sometimes it is worth looking into),
but from a quick calculation, based on knockout-1.2.1.debug.js, the
jQuery-specific stuff amounts to almost 10% of the uncompressed code.
I guess that's not a big deal with regards to size, I'm more
interested in the fact that the code isn't completely agnostic about
jQuery's existence. (What? You mean there are people that don't use
jQuery?!?! Heretics!!!)
Just a few quick examples - the following comments are in the code
base:
// For click events on checkboxes, jQuery interferes with the
event handling in an awkward way:
// it toggles the element checked state *after* the click event
handlers run, whereas native
// click events toggle the checked state *before* the event
handler.
// Fix this by intecepting the handler and applying the correct
checkedness before it runs.
What if Dojo, MochiKit, YUI, etc. "interferes with the event handling
in an awkward way?" Should Knockout provide checks for those as well?
Why not? There are a few other places where jQuery apparently does
things that Knockout is trying to be "pro-active" about working
around, but why? What if I am not using jQuery? Why should I have the
extra baggage of that code?
On the other hand, we have comments like this, too:
// Based on jQuery's "clean" function, but only accounting for
table-related elements.
// If you have referenced jQuery, this won't be used anyway - KO
will use jQuery's "clean" function directly
Apparently, jQuery has some nice utilities/constructs that Knockout
can leverage if available, which means the code that "won't be used
anyway" just became additional baggage. Well, what if other libraries
do the same? Should we have checks for those, as well? Why not?
It seems to me that Knockout can have its cake and eat it, too, if
both of these scenarios are planned for by the code base. At least
with the scenario where an external library may very well have better
abilities than Knockout, it could provide a hook such that a separate
adapter/compatibility layer, of sorts, could be used with each type of
external library, if desired.