/// Saturday, December 3

Behaviour.NET - Real Open Source AJAX for .NET

Real open source meaning Apache License 2.0 instead of the mess with AJAX.NET.

So I thought I had discovered a better way to do AJAX. Well, it looks like the MS Atlas folks and I think alike. I haven't really looked Atlas, and today I saw a screenshot of it with the word behaviour. What's funny is behaviours are the foundation of Behaviour.NET, a standalone AJAX library for my Gamba framework. I'd have to look at some samples to verify. What is that old adage? "Great minds think alike." I won't go that far, but this seems a better approach than what I've seen.

If you remember my previous article Helpers or Components? I could not decide whether to create an AJAX API using helper functions or a lightweight component framework. After some contemplation it's my humble opinion helper functions are evil. We're back to ASP spaghetti again. Let's compare the two approaches, here's the helper function style:

class Test(AjaxController):
    def Foo():
        ViewMethod = FooView

    def SayHello() as string:
        ContentType = Content.TextPlain
        return "Hello world!"
<!-- Test.FooView.tpl -->
<%= CreateButtonDoRemote("Invoke Remote", Urlize("SayHello")
        , {"onsuccess" : "$('input1').value = request.responseText;"
        , "onfailure" : "alert('Unable to get information from server.')"}
    )
%> &nbsp; <input id="input1"/>

It's typical ASP coding. Here's how it's done with Behaviour.NET, with behaviours code residing in the controller.

class Test(AjaxController):
    def Foo():
        button = Button("button1")
        with method = RemoteMethod(Test, "SayHello"):
            OnSuccess += Prototype.SetValue("input1")
            OnFailure += Prototype.MsgBox("Unable to get information from server.")
        button.OnClick += Prototype.InvokeRemote(method)

        Behaviours.AttachBehaviour(button)
        ViewMethod = FooView

    def SayHello():
        ContentType = Content.TextPlain
        return "Hello world!"
<!-- Test.FooView.tpl -->
<input id='button1' type='button' value="Invoke Remote"/> &nbsp; <input id="input1"/>

It's a little bit more coding, but here are some advantages off the top of my head

One disadvantage is a slight performance loss, but that's minimal. I've looked at some implementations of AJAX generic helper functions and they use a maze of functions to generate a script. These objects are very light and for now all they do is encapsulate some javascript code. This lightweight component framework coincidentally fits in very well with Gagamba, my plans for a fully componentized version of Gamba. I wanted to do a basic core framework first before starting Gagamba.

Oh, I almost forgot. Thanks to Ben Nolan, the author of the Behaviour JavaScript library for inspiration.

Comments:

Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?