[dojo-contributors] deferredRequire extension

ben hockey neonstalwart at gmail.com
Sat Jun 2 20:50:32 EDT 2012


guys... take this off the list or we will block your posts.

--
ben...

On Jun 2, 2012, at 12:12, Ken Benjamin <kenbenjamin at kenbenjamin.net> wrote:

> Sasha,
>  
> What you say is not correct. Everything that is an object in Javascript has a prototype, including Function. require() is just a ordinary function which means it is subclassed off of Function. There isn’t any way for it to be anything else and be callable.
>  
> If you don’t believe me, load a dojo.js, open your browser debugger and type: require.prototype. I think the confusion is that all the functions in require() are defined inside the constructor so to see everything you would want to look inside require.prototype.constructor.
>  
> As for your test case, it is all messed up. I don’t know how you built your example but you are not using the code I provided. I’m attaching the updated code with updated documentation (just rename it from .txt back to .js before using it). See the example in there to know how to run it.
>  
> I have already integrated my updated code into the app I’m building and it works perfectly exactly as I describe it. I know for sure it works, at least in all the cases I’ve tested so far which include passing dojo.config, not passing dojo.config, passing multiple modules, and passing single modules. I can’t think of any other scenarios that are supported so that pretty well covers being sure it works.
>  
> Ken
>  
>  
> From: Sasha Firsov [mailto:suns at firsov.net] 
> Sent: Saturday, June 02, 2012 5:44 PM
> To: Ken Benjamin
> Cc: dojo dev.
> Subject: Re: deferredRequire extension
>  
> Nice idea, but in DTK require() is not regular object with prototype 
> 
> require.prototype
> would work only inside of your "dojo/_base/dynamic" and would not be populated within custom methods "require" :( 
> See that on 
> http://simulationlabs.com/dojo/DojoPlay2012/libcommon/DTK1.7/util/doh/runner.html?testModule=lib/AMD/test/deferredRequireTest&paths=lib,../../../lib
>  
> lib/AMD/test/deferredRequireTest.js has test case for require.dynamic.
> 
> What could potentially work, is AMD post-processor since it will accept pre-made module:
> 
> define( ["require!dynamic"],function( require )
> {
>     require(["myMod"]).then( function(myMod){} );
> }
> 
> Let me check postprocessor availability...
> Sasha
> 
> PS. why you trying to substitute arguments in callback? You could use it as is:
>         require.prototype.constructor.dynamic = function()
>         {
>                 var d = new Deferred();
>                 var callback = function()
>                     {
>                         d.resolve(arguments); 
>                     };
>                 require.apply(this, arguments);
>                 return d;
>         };
> 
> 
> On 2012-06-02 01:20, Ken Benjamin wrote:
> How about this, which extends all instances of require() to have
> require.dynamic(). Parameters are the same as for require() excluding a
> callback but the return is a Deferred.
>  
> Proposed dojo/_base/dynamic.js:
>  
> require(['dojo/_base/Deferred'], function(Deferred){
>   require.prototype.constructor.dynamic = function(
>          config,       //(object, optional) hash of configuration
> properties
>          dependencies //(array of commonjs.moduleId) list of
> modules to be loaded before applying callback
>   ){
>          var d = new Deferred();
>          var callback = function(){
> d.resolve(Array.prototype.slice.call(arguments)); }; // callback Deferred
> with list of modules            
>          require.apply(this, (config instanceof Array) ? [config,
> dependencies, callback] : [dependencies, callback]);
>          return d;
>   };
> });
>  
> Example use:
>  
> require([
>          'require', // local context require
>          'dojo/_base/dynamic'
>   ],
>   function(require){
>          var widgets = ['dijit/form/Button', 'dijit/form/Textbox'];
>          require.dynamic(widgets).then(function(Button, Textbox){
>                  // do something with Button and Textbox
>          });
>   }
> );
>  
>  
> <dynamic.js.txt>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-contributors
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20120602/339a614c/attachment.htm 


More information about the dojo-contributors mailing list