Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.5.8

Request #9434 callback as closures
Submitted: 2006-11-23 20:25 UTC
From: akutin at symcor dot com Assigned: jeichorn
Status: Wont fix Package: HTML_AJAX (version 0.5.0)
PHP Version: 5.1.6 OS:
Roadmaps: (Not assigned)    

 [2006-11-23 20:25 UTC] akutin at symcor dot com (Alex)
Description: ------------ In async mode it appears to be usefull to define callbacks as closures. When the response time is noticeable values of global variables might change based on user actions during the request. Test script: --------------- <html> <select id="select1" onchange="onSelectBoxChange( this)"> <option value="1">First list</option> <option value="2">Second list</option> <option value="3">Third list</option> </select> <select id="select2"> </select> </html> // Javascript // ajaxInterface is an instance of an ajax stub with callbacks in async mode. /* the code populates values in one select box (select2) based on selection in another (select1). If during the ajax request user changes the selection in select1 the result gets dropped (there would be antoher result */ function onSelectBoxChange( selectbox) { var selection = selectbox.value; ajaxInterface.dispatcher.callback['listValues'] = function( result) { if( selection != document.getElementById( { // selection changed, drop the result } else { // display values } } ajaxInterface.listValues( selection); } to allow closures HTML_AJAX.js lines 1624 - 1633: if ( this.mode == "async" ) { request.isAsync = true; if (this.callback[callName]) { var self = this; request.callback = function(result) { self.callback[callName](result); } } } else { request.isAsync = false; } could be changed to if ( this.mode == "async" ) { request.isAsync = true; if (this.callback[callName]) { var handler = this.callback[callName]; request.callback = function(result) { handler(result); } } } else { request.isAsync = false; }


 [2006-11-27 17:32 UTC] auroraeosrose at php dot net (Elizabeth Smith)
Unfortunately, IE cannot be trusted with closures and this may break BC, we really don't want to mess up existing code. However the ability to have closures for callbacks might be important and is functionality that should be added. We just need to make sure it doesn't cause problems from someone who is passing in a callback class and using utility methods etc on it. Josh mentioned adding a method to register closures that way you don't have to rely on the constructor to set your callback - something to add new callback properties. Assigning this to Josh (my javascript isn't up to this)
 [2017-02-02 21:57 UTC] cweiske (Christian Weiske)
-Status: Assigned +Status: Wont fix -Roadmap Versions: 0.6.0 +Roadmap Versions:
Nobody will do that.