zumbrunn.com

E4X Mocha Objects

The next generation of Mocha Objects might evolve in a direction that would look something like the following, tying in tighter with the hard-coding environment of Helma:

./Site/list.view.control


    // function at Site.prototype.views.list.control(that)

    if (this.topics.count()) {

        that.topics = {};

        for (var topic in this.topics) {

            that.topics.name = this.topics[topic].name;

            that.topics.count = this.topics[topic].comments.count();

        }

    }

./Site/list.view


    <table border="1">

        <tr if="topics">

            <th lookup="true">Topic Name</th>

            <th lookup="true">Comment Count</th>

        </tr>

        <tr for="topics" class="rowcolor{ $topics % 2 }">

            <td>{ topics$.name }</td>

            <td if="!topics$.count" lookup="true">

                No comments yet</td>

            <td if="topics$.count == 1" lookup="true">

                { topics$.count } comment</td>

            <td if="topics$.count > 1" lookup="true">

                { topics$.count } comments</td>

        </tr>

        <tr if="!topics">

            <td colspan="2" align="center" lookup="true">

                This list is empty</td>

        </tr>

    </table>

./Site/list.control


    // function at Site.prototype.controls.list

    var content = {

        main : this.views.list.render()

    };

    var page = Page.views.default.render(content);

    return page;

this.views.list.control() is invoked when the list view is rendered.

When it is invoked, "that" is the object which was passed as parameter

of the render() method or otherwise an empty/default object. "that" is

the object that will be used as the Javascript context when rendering

the view. 

Views would be E4X Javascript XML objects. When Helma would render

these views, it would parse them for "lookup", "if" and "for"

attributes and then evaluate them in the context of "that". 

When parsing the "for" attributes, Helma would loop through the indicated object (topics) with "for(var $topics in topics)" and repeat the specified element (the table row) with topics$ == topics[$topics]

When parsing the "lookup" attributes, Helma would check if a lookup

handler function exists and if so would apply it to the element's

content.

this.controls.list would be the function that is called in order to handle the request, similar to todays this.list_action.

9.12.2005, 9:02