See Joel Program

July 31, 2008

A Client Event Pool in JavaScript

Filed under: ASP.NET AJAX — Joel Rumerman @ 9:26 pm

One of the most useful programming concepts that my company has created over the past 16 months is also one of the simplest things that I’ve ever coded. It’s a client-side event pool that lives on the browser and that you interact with through JavaScript.

It’s purpose is simple: to allow arbitrary code to execute when an event is raised. You can think of it as a simple observer pattern implementation.

(You can download the source code here.)

To see just how simple it is, take a look the definition of the ClientEventPool … all 22 lines of it.

_ClientEventPool = function() {
    _ClientEventPool.initializeBase(this, null);
};
_ClientEventPool.prototype = {
    initialize: function() {
        _ClientEventPool.callBaseMethod(this, 'initialize');
        this._localEvents = this.get_events();
    },
    addEvent: function(eventName, handler) {
        this._localEvents.addHandler(eventName, handler);
    },
    removeEvent: function(eventName, handler) {
        this._localEvents.removeHandler(eventName, handler);
    },
    raiseEvent: function(eventName, sender, args) {
        var h = this._localEvents.getHandler(eventName);
        if (h) {
            h(sender, args);
        }
    }
};
_ClientEventPool.registerClass("_ClientEventPool", Sys.Component);
window.ClientEventPool = $create(_ClientEventPool, {"id":"ClientEventPool"}, null, null, null);

To use the event pool, I can simply register a handler for the event, and then raise the event like so.

ClientEventPool.addEvent("Test", function(sender, args) { alert("hello!"); });
ClientEventPool.raiseEvent("Test", this, Sys.EventArgs.Empty);

(In case you’re interested, the event pool relies upon ASP.NET AJAX Sys.Component’s .NET-style eventing mechanism, but in reality, using Sys.Component was just a convenience. Because Functions in JavaScript are nothing more than objects, executing functions that are assigned to properties, is really easy and is the concept of .NET delegates, are built into the language. This object could have easily been created without using anything from ASP.NET AJAX.)

(Shameless above-the-fold plug: If you’re a control developer who adds AJAX functionality to their server controls, you might be interested in my new book: Advanced ASP.NET AJAX Server Controls for .NET 3.5. Also, there’s a preview chapter in CoDe magazine.)

(more…)

July 29, 2008

CoDe Magazine – Book Chapter

Filed under: ASP.NET AJAX — Joel Rumerman @ 7:27 am

Yesterday, CoDe Magazine published Chapter 11: Adding Client Capabilities to Server Controls Using the ASP.NET AJAX Control Toolkit from Adam’s and my book: Advanced ASP.NET AJAX Server Controls for .NET 3.5. Pretty cool stuff!

Check out the free chapter and let us know what you think!

July 28, 2008

Cuil.com

Filed under: Searching, Technology — Joel Rumerman @ 7:26 am

It’s rare that anything receives above the fold respect from both CNN.com and NPR on the same day so when a new search engine, Cuil.com (pronounced Cool) achieved such recognition, I had high hopes for the new search engine.

Here are my initial impressions.

  1. The first time site load was slow even though it’s mainly a single search box. It acted like most other sites do when they get hammered by a lot of web traffic due to a major press day. BUT, it did come up, which is better than a lot of other sites. Subsequent hits were quick as they seemed to cache everything on my browser correctly.
  2. My HCI professor wouldn’t be happy with the black background, but I didn’t mind it so much. It’s a bit different and a bit edgier than they should have gone if they’re trying to attract the main stream search market, but as a tech geek, I’m okay with it.
  3. The search results are laid out in a nice way, but again, took too long to come back. We’re used to Google‘s sub-second search results and frankly, if you want to be a Google killer, you’d better perform as good as they do
  4. The search results are not good. As you know if you my previous post, I recently wrote a book titled “Advanced ASP.NET AJAX Server Controls.” I entered that into the search box and my results were … wait for it … hold … hold … nothing. That’s embarrassing. The book is being sold in multiple countries, by multiple online and brick and mortar websites. Google’s results contain these listings. If you’re going to crawl 120 billion web pages and claim that you’re crawling more information than Google, you need to do a much better job.

Conclusion: I’ll check back in a week and see how it works then, but they just lost the initial round.

July 9, 2008

Advanced ASP.NET AJAX Server Controls for .NET Framework 3.5 Released!

Filed under: AJAX, ASP.NET AJAX, Book — Joel Rumerman @ 1:20 pm

Phew … it’s out.

This past week, Adam’s and my book: Advanced ASP.NET AJAX Server Controls for .NET Framework 3.5 released to online retailers. It should be available in your brick & mortar stores either later this week or earlier next week. If anybody’s got any questions about it, pass them along!!

Advanced ASP.NET AJAX Server Controls

Advanced ASP.NET AJAX Server Controls

Blog at WordPress.com.