Igor Vaynberg a écrit :
On 11/10/06, Vincent demay <[EMAIL PROTECTED]> wrote:

>
> c) we have partial page updates of multiple components in a single
> request -
> do any of those frameworks have it? i briefly looked at ricko which had
a
> similar ajax-envelope response that can encapsulate markup for multiple
> parts of the page that need to be updated a while back - but it was
still
> very immature.
I wrote something like that in Wicket Dojo Contrib (DojoUpdateHandler)


fair enough - and how much code did you have to write for that? you need to
construct an xml envelope that contains markup from multiple components -
then on javascript side you need to be able to break down that envelope,
pull the markup out, and put it into the right places on the page. i wouldnt
imagine dojo provides stuff to make a conrner case like this easier.
I used AjaxRequestTarget to construct the envelope
and here is the client-side code. It is not perfect but it work (ie remove CDATA is not as clean as I wanted but I not sure is mandatory) :

function updateComponents(/** node */ ajaxRequest){
    //get the first component in ajaxRequest
    var component = dojo.dom.firstElement(ajaxRequest, "component");

    var currentId;
    var currentContent;
    var node;
while (component != null){
        currentId = component.getAttribute("id");
        //get content...
        currentContent = dojo.dom.innerXML(component.firstChild);
        //...and remove CDATA
currentContent = currentContent.substring(9, currentContent.length - 3); //find the node to replace in document
        node = document.getElementById(currentId);
//replace it
        var range = node.ownerDocument.createRange();
         range.selectNode(node);
       var fragment = range.createContextualFragment(currentContent);
       node.parentNode.replaceChild(fragment, node);
//get next component
       component = dojo.dom.nextElement(component, "component");
    }
}



> d) and the biggie - header contributions. we went through a lot of
> pain to
> ensure that if you have a <script> or a <link> to js markup in the
_ajax_
> response - it will be properly executed by the browser. this is key for
> component oriented frameworks. afaik neither dojo, nor scriptaculous,
nor
> ricko, nor anyone else out there provide this functionality.


I understand that but a framework like dojo does not need a such
functionality because every script could be called by dojo.require()
function


assuming that everyting is written in dojo. what about normal components
that do include scripts they need loaded at ajax render. if something
includes <script>alert('foo')</script> in their markup and that is made
available through an ajax render that script needs to be executed. this is where a lot of our javascript code is, and that would have to be rewritten for dojo anyways. browsers normally wont do that if that markup is added via
a dom op, so we need to do it ourselves.
Dojo dj_eval method do that :

function dj_eval(/*String*/ scriptFragment){
// summary: Perform an evaluation in the global scope. Use this rather than calling 'eval()' directly. // description: Placed in a separate function to minimize size of trapped evaluation context.
   // note:
// - JSC eval() takes an optional second argument which can be 'unsafe'. // - Mozilla/SpiderMonkey eval() takes an optional second argument which is the
   //       scope object for new symbols.
return dj_global.eval ? dj_global.eval(scriptFragment) : eval(scriptFragment); // mixed
}

and this function can read distant *.js :

/**
* Reads the contents of the URI, and evaluates the contents.
* Returns true if it succeeded. Returns false if the URI reading failed.
* Throws if the evaluation throws.
* The result of the eval is not available to the caller TODO: now it is; was this a deliberate restriction?
*
* @param uri a uri which points at the script to be loaded
* @param cb a function to process the result of evaluating the script as an expression (optional)
*/
dojo.hostenv.loadUri = function(uri, cb /*optional*/){
   if(this.loadedUris[uri]){
       return 1;
   }
   var contents = this.getText(uri, null, true);
   if(contents == null){ return 0; }
   this.loadedUris[uri] = true;
   if(cb){ contents = '('+contents+')'; }
   var value = dj_eval(contents);
   if(cb){
       cb(value);
   }
   return 1;
}


besides, dojo is huge - modular or not. we have something that is compact
and it works.
Yes I agree with you, dojo is huge but It could help developpers to be more efficient, it is just my opinion. And I agree with you when you say that your implementation is more compact and works properly. It is very nice and i based my dojo development on it (AjaxRequestTarget for exemple).

Thanks for your answer Igor

-igor

--
Vincent

Reply via email to