That only works when all the modules are define()d in pre-req order.
On Mon, Apr 30, 2012 at 12:25 PM, Patrick Mueller <pmu...@gmail.com> wrote:
> Am I right in thinking that AMD is factory-on-define, at least in the caseIt has not been specified, but seems like it is time to do so. Thanks
> of no pre-reqs, or perhaps even the case of 'has pre-reqs, but they've
> already been loaded'? If so, I think that should be spelled out in the AMD
> spec - here, I guess: https://github.com/amdjs/amdjs-api/wiki/AMD . Maybe
> it's there and I missed it?
for taking the time to describe the issue.
As Taka mentions, it depends on the loader. requirejs does
"define-on-require" ...
The only problem I see with making this 'default' is that it breaks implementations which were dependent on this behavior. I assume there exists code which is dependent on this behavior.
Just to make sure we're on the same page, I used 'factory-on-require' which I assume you are calling 'define-on-require'. By 'factory-on-require' I mean "a module's factory function is only ever executed in response to a require() invocation for that module, not by a define() call of that module".Are we talking about the same thing? I hope so. :-)
I’d like to get some clarification. Is anyone considering and/or implementing the following order?
· "about to require..."
· "some/module factory is being run"
· "some/dependency factory is being run"
· "some/module should be loaded"
This seems more in line with “factory-on-require,” as opposed to, say, “factory-upon-being-depended-on.”
Cf. James’s earlier reply in a related thread. I just want to make sure all involved are aware of the subtle difference he describes there. It seems there are at least three alternatives, even though only two names are being used.
to the best of my knowledge, dojo is 'factory-on-require' - see http://jsfiddle.net/neonstalwart/RAXkb/ (snippet follows)
The only problem I see with making this 'default' is that it breaks implementations which were dependent on this behavior. I assume there exists code which is dependent on this behavior.
I don't think any "good" code would depend on this behavior, in fact it kinda scares me to think about what kind of code would break should an AMD loader switch from factory-on-define to factory-on-require.
AMD modules should only care about these things:
1) Dependencies2) Export/Factory3) [Optionally] Own Module ID
Modules should only care that their dependencies are defined/exist when the factory function executes. Modules should not care about how/when they are loaded, as long as they are there when the factory function is invoked.
Nothing in the factory function will execute until dependencies are resolved in either scenario (factory-on-define or factory-on-require). Thus I can't see how/why it would break any pre-existing code to make the switch from factory-on-define to factory-on-require.
-
On Mon, Apr 30, 2012 at 22:34, Ben Hockey <neonst...@gmail.com> wrote:
to the best of my knowledge, dojo is 'factory-on-require' - see http://jsfiddle.net/neonstalwart/RAXkb/ (snippet follows)
I believe I'm seeing a problem just with Dojo at the moment, and so following up there.
To be clear: proper AMD does run factory on define(). I'm pretty sure most, if not all, of the other loaders agree with this.
Lastly, I would *strongly* encourage you to reconsider the way you've decided to express your modules. The "pure AMD way"....using no absolute module id's and one module def per file will make your code much more portable and optimizable, and should control complexity.
On Tue, May 1, 2012 at 14:52, Rawld <rg...@altoviso.com> wrote:
To be clear: proper AMD does run factory on define(). I'm pretty sure most, if not all, of the other loaders agree with this.
But in a later post to this thread you respond to a post from James ...
On Tue, May 1, 2012 at 14:57, Rawld <rg...@altoviso.com> wrote:
On 04/30/2012 01:39 PM, James Burke wrote:
End result: I suggest we just agree on "define-on-require" as theI agree...particularly since dojo/backdraft has always been this way in pure AMD mode :)suggested execution behavior and update the spec page with that
language.
So, I'm confused. Are you in the factory-on-define camp or in the factory-on-require camp?
I'm also confused by some of your terminology - what do the following mean:
- proper AMD- pure AMD
You've also use "legacy" before, but that just may be in reference to Dojo. If it's applicable to AMD itself, please define.
Are these in the spec?
Lastly, I would *strongly* encourage you to reconsider the way you've decided to express your modules. The "pure AMD way"....using no absolute module id's and one module def per file will make your code much more portable and optimizable, and should control complexity.
I'm following the AMD spec here, as near as I can tell - point out to me where I'm not. If I am following the spec, I don't see how my code could not be portable.
On 05/01/2012 01:29 PM, Patrick Mueller wrote:The spec allows specifying an absolute module id. But this is strongly discouraged.I'm following the AMD spec here, as near as I can tell - point out to me where I'm not. If I am following the spec, I don't see how my code could not be portable.
And once you eliminatethe absolute module id, you must have a 1-to-1 arrangement of modules to resources.
Lastly, depending onthe factory scan to determine dependencies is not a required feature of AMD...it's a "MAY" clause. So I would recommend specifying each modules dependency explicitly.
On Mon, Apr 30, 2012 at 2:07 PM, Patrick Mueller <pmu...@gmail.com> wrote:
> On Mon, Apr 30, 2012 at 16:39, James Burke <jrb...@gmail.com> wrote:
> Just to make sure we're on the same page, I used 'factory-on-require' which
> I assume you are calling 'define-on-require'. By 'factory-on-require' I
> mean "a module's factory function is only ever executed in response to a
> require() invocation for that module, not by a define() call of that
> module".
>
> Are we talking about the same thing? I hope so. :-)
Ah yes, sorry, the voices in my head did a swap of words, I meant
"factory-on-require" as you outline above.
James
The difference becomes important while simulating a "shim" functionality with plain AMD API:define('underscore', ['js!path/to/underscore.js'], function(){return _})define('backbone', ['js!path/to/backbone.js'], function(){return Backbone})require(['underscore'],function(_){// intentionally nesting to insure bb's eval// happens after underscore's eval is donerequire(['backbone'],function(bb){// do something with bb, _})})