David said:
David said:
David Mark wrote:
David Mark wrote:
David Mark wrote:
Thomas 'PointedEars' Lahn wrote:
David Mark wrote:
[...]>> I buy into that pattern. Works great.
[...]
Typo (missing ev).
var target = APE.dom.Event.getTarget(ev);
I can't see using a library for this. And what's with the long-winded
"namespace?" I don't care for that either.
An abstraction is appropriate here.
I'm fine with abstractions, provided they are well thought out.
Regarding the namespace:-
APE - the library namespace.
dom - the dom module. This module may be used with only dependency of
APE.js. APE.js, fully commented and uncompressed, is about two
screenfulls of code (something like 6k, uncompressed, with comments).
Can we skip the marketing?
dom.Event - for dealing with dom events. If these methods were placed
directly on dom, they would need renaming. Consider:-
APE.dom.getTarget; // what sort of target?
APE.dom.Event.getTarget; // gets an event target.
Does APE.dom.getEventTarget look better? I would have to consider other
methods in the dom.Event package (how they woul be renamed, if they
would make sense, etc).
Well, I have found that a "flat" namespace works fine. No collisions
and no self-imposed performance penalties.
It might "work", but it doesn't define discreet modules as clearly.
No, it works (not "works"). But I see what you are saying (it can
help you develop the library). Might want to think about how you
could filter that stuff out in the release process.
I want to know what is defined where and what depends on what.
What should be filtered? I don't have much idea for wanting to filter
things. Even the rollup ape-ep-dom-min.js is something like 15k. That is
before gzip, of course. After gzip it is smaller.
For something that small, there isn't really much need to try and filter
out unused functions.
[...]
Yes. Chrome is clearly faster than the rest.
CHrome may have some sort of upvar optimization.
....]
I was saying not to mix them, but the higher-level should certainly
call upon the lower to attach the listeners. Are you saying you don't
do that?
Any of what?
Browser bugs/issues. EventPublisher doesn't know about any quirks of
events, bubbling. NOne of that.
And - like seemingly all JS written these days - it plows straight
into a language-imposed roadblock for no reason at all.
The solution to the dojo problem has side effects even after going to so
much effort try try and work, even borrowing code from others, trying to
make sense of it, trying to get it to work, yet still causing system
side effects and still relying on faulty abstractions and complicating
the entire mess with all that wacko typechecking stuff.
No kidding. I've already reviewed them (and changed them in my
branch, of course). There's an isArray too and all three are called
from all over the place (but not in my branch). I've tried to tell
them. Some people don't want to hear that they are wrong so many
times and will make any excuse to stick with what they are doing. In
open source, every contributor wants to be a genius. One guy ran off
and wrote his own loader to mimic the one I did for them. Copied all
of the is* crap, including typeof xyz == 'array'. He wanted "proof"
that that wouldn't work in "all browsers" (hard to even phrase
it).
Of course, he quietly changed it after making me beat him
over the head repeatedly with it and then bitched like an obsessive
schoolgirl that it was my poor "social skills" that caused all of the
problems.
Yeah, I don't need to make friends with incompetent
twits with ego issues. I haven't posted there in months and he is
_still_ over there writing fucking _books_ about me.
Yeah, tell me something I don't know. I tried to start by explaining
the very simplest and lowest-level issues (e.g. window.eval). Got
nowhere. **** it if they don't want to listen (or just copy what I
did). Everyone wants to invent the next great thing. Nobody wants to
do actual work. One guy said, "I'd rather be relevant than right".
I'm sure that was a "swipe" at my library (LOL).
Supercilious comments such as "lets be pragmatic" or "lets try and just
get it done" turn a blind eye to a problem.
No kidding. I never asserted it didn't. All you have to do is
compare the branch to the trunk. It's like night and day. For one, I
removed _all_ of the browser sniffing. Unsurprisingly, a side effect
is that it loads and runs much faster (obvious to anyone looking at
it) and is considerably smaller as well. They wanted me to draw
pictures (e.g charts) for them and I didn't have the time or
interest. Other than a couple of people near the top of the
structure, they want nothing to do with it (because they _had_ nothing
to do with it).
The code of dojo 1.3 is of very poor quality. It appears to have
borrowed from various sources, yet still manages silliness like the
isFunction below. I've interspersed my comments with (GS):-
| dojo.isFunction = (function(){
| var _isFunction = function(/*anything*/ it){
| // must evaluate separately due to bizarre Opera bug. See #8937
|
| var t = typeof it;
|
|
| // (GS) `it can *never* be false-ish?
| // (GS) `it instanceof Function` is superfluous; if t == "function" is
| // false, then `it instanceof Function` can never be true.
| // Boolean
| return it && (t == "function" || it instanceof Function);
| };
|
| return dojo.isSafari ?
| // only slow this down w/ gratuitious casting in Safari (not WebKit)
| function(/*anything*/ it){
|
| // (GS) Serializing an object to see does not convert to string
| // (GS) "[object NodeList]" does not mean the object is a function.
| if(typeof it == "function" && it == "[object NodeList]"){
| return false;
| }
| return _isFunction(it); // Boolean
| } : _isFunction;
| })();
The isSafari thing checks to see if an object's toString results in
"[object NodeList]". As most of us know, Safari implements callable
objects such as forms and images:-
javascript: alert(typeof document.images)
"function" in Safari, so the dojo isFunction doesn't let Safari's
document.childNOdes pass, but lets pass document.images. It makes one
wonder what they would want this function to actually do.
You'll also get that function returning true for Callable RegExp in some
browsers, false for callable regexp in other versions.
javascript: alert(typeof /a/)
Safari 4, FF2 "function"
(it is is callable)
FF3.5
"object"
(it is callable)
So the dojo.isFunction is not defined, has inconsistent results.
They also have the isString function used:-
| dojo.isString = function(/*anything*/ it){
| // summary:
| // Return true if it is a String
| return !!arguments.length && it != null && (typeof it == "string" ||
| it instanceof String); // Boolean
| }
|
Again, we have the check `it instanceof String` which is superflous.
And the isArray:-
| dojo.isArray = function(/*anything*/ it){
| // summary:
| // Return true if it is an Array
| return it && (it instanceof Array || typeof it == "array");
| // Boolean
}
- which I recently commented on in ES-discuss.
See my reply to Mike Samuel's post:
https://mail.mozilla.org/pipermail/es-discuss/2009-December/010406.html
Mike Samuel actually seems a bit upset that I pointed out that his
argument is based off a very poor standard.
What is really sad is that discussions of this very same `isFunction`
function from dojo over two years ago. Two years and SOS.
What is even more sad is that the isFunction checks are totally
unnecessary.
When you get yourself in that position where you have to try and figure
out if the object's toString looks like "[object Nodelist]" it's time to
wake the **** up and realize that "this is dumb" and "lets not do that".
What's even more absurd is that developers readily accept this dumb
code, for which the shortcomings have been explicitly and specifically
discussed, with failure cases demonstrated. Yet developers accept this
as de facto industry standard.
What is even more absurd, these developers actually try to make Web
Standards proposals based on this shit.
I consider that a very minor issue (if an error at all). If the
calling app has errors, it has errors.
The issue I experienced one day, when my manager asked me to hide a
button on a certain condition. It was the day before build. I told him
that it sounded like a simple change, but that I would not be willingto
do it before the build (how about not wing it into production?)
No good, the boss says. Put that in and hide the button on this page.
i did it and showed it to him and he thanked me. I left to go early that
day. Early means before 7pm and that was really early. Often I left
after 8.
So I was on my way and I had an appointment. I had a massage scheduled.
Well I'm on my way, and I have a few minutes so I stop at the park to
stretch out and the phone rings. My boss calls me back in t owork.
Turns out that change broke the entire page, during one user story. I
got back and realize the cause problem pretty quickly.
In that user story, the button had been hidden by another guy on the
team, but on the server, in the JSP as:-
<c:if test="${!someStrangeCondition}">
<button id="newRecord">new</button>
</c:if>
Turns out my boss asked him to hide the button in one user story and me
to hide it in another.
And so my code, which was having:-
YAHOO.util.event.onDOMReady(hideNewRecordButton);
- was throwing errors in the callback. Obviously that woud have been
avoided if I had done careful test to make sure the element existed as:-
if(newButton && newButton.style) {
}
But I didn't and so the error was on the page and was causing all the
domReady callbacks to fail, breaking the entire page.
I thought about it and realized that the same phenomenon does not occur
with dom events.
document.addEventListener("click", errFunc, false);
document.addEventListener("click", goodFunc, false);
if errFunc throws, then goodFunc still runs. The error is thrown
asynchronously. That makse perfect sense so I copied that.
Sure it does. I saw you attach a click to the document with it. (?)
That is about the *usage*. EventPublisher does not know anything about
document. It only knows that it adds a property to an object and the
property is function. It doesn't discern between host object or native
object. You could probably, though I wouldn't recommend, ad a callback
for Math.round. I have no idea why you would want to do that, but I
think it should work.
[...]
Can be useful, but most scripts are so simple that it's overkill.
It actually keeps everything separate and simple. EventPublisher is one
thing I got very right.
It is not confusing at all. I learned that from Dan Steinmann about 10
years ago.
You can have an object:-
function Car(){
}
(function(){
// Private static.
function cancelCarAnimation(){ }
Car.prototype = {
onstop : Function.prototype,
stop : function(){
if(this.isRunning) {
cancelAnimation(this)
this.isRunning = false;
this.onstop;
}
};
[...]
APE.dom.Event is a different matter. That is specifically for DOM event
handling.
Aha! Fair enough then. You'll forgive me if I don't go back and
rewrite my previous comments. If it can be deconstructed, then all is
well.
What do you mean by deconstructed?
Is there an event layer with a "custom event" layer on top of it? If
not, there is either tangling or redundancy.
No, there is no layer with "custom event" layer on top of it.
APE.dom.Event is just a few functions for things like getTarget,
addDelegatedFocusCallback, and such.
[...]
I hate GG.
Then go download Thunderbird and sign up for an account on
eternal-september.org.
Time for new years!