Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 364214

Summary: Include a minimal window.require in global.js
Product: [ECD] Orion Reporter: Mihai Sucan <mihai.sucan>
Component: EditorAssignee: Mihai Sucan <mihai.sucan>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe, mihai.sucan, Silenio_Quarti, simon_kaegi
Version: unspecified   
Target Milestone: 0.4 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Mihai Sucan CLA 2011-11-19 06:33:06 EST
The global.js file has a minimal window.define function for the cases when requirejs is not used, and that's perfect for integrators which do not deal with the usual case of web-based loading of the scripts. (like our case at Mozilla).

We would also like a minimal window.require function so we don't have to integrate the whole requirejs.

Will submit a patch. Thank you!
Comment 1 Mihai Sucan CLA 2011-11-19 06:47:36 EST
Proposed patch:

https://github.com/mihaisucan/orion.client/tree/bug-364214

Please review the patch and let me know if further changes are needed. Thank you very much!

(This makes it easier for us to integrate Orion. Otherwise we'll have to include requirejs, which is overly complex for what we need.)
Comment 2 Felipe Heidrich CLA 2011-11-21 14:17:17 EST
it looks fine to me.


We didn't add window.require because we did not need it. Will you actually be using this method or are you adding it for consistency sake ?
Comment 3 Mihai Sucan CLA 2011-11-21 14:18:44 EST
(In reply to comment #2)
> it looks fine to me.

Great!


> We didn't add window.require because we did not need it. Will you actually be
> using this method or are you adding it for consistency sake ?

We are actually going to use it.
Comment 4 Felipe Heidrich CLA 2011-11-21 14:31:56 EST
Note that our current implementation for define is as follow:
window.define = function(deps, callback, moduleName) 

The actual signature for define is:
window.define = function(moduleName, deps, callback) 

The problem of using the actual signature is that it would force all user to pass the optional moduleName to define, which has the problem described in 
http://requirejs.org/docs/api.html#modulename
"You can explicitly name modules yourself, but it makes the modules less portable -- if you move the file to another directory you will need to change the name. It is normally best to avoid coding in a name for the module..."

thoughts ?
Comment 5 Mihai Sucan CLA 2011-11-21 14:47:51 EST
(In reply to comment #4)
> Note that our current implementation for define is as follow:
> window.define = function(deps, callback, moduleName) 
> 
> The actual signature for define is:
> window.define = function(moduleName, deps, callback) 
> 
> The problem of using the actual signature is that it would force all user to
> pass the optional moduleName to define, which has the problem described in 
> http://requirejs.org/docs/api.html#modulename
> "You can explicitly name modules yourself, but it makes the modules less
> portable -- if you move the file to another directory you will need to change
> the name. It is normally best to avoid coding in a name for the module..."
> 
> thoughts ?

Well, the current Orion code uses deps, callback, moduleName, and it works with the current window.define implementation from global.js.

We don't have any specific needs/requirements for making window.define compatible with the actual requirejs API, as long as the Orion code can be used with the define() and require() shims from global.js. That's what matters for us.

Thanks!
Comment 6 Mihai Sucan CLA 2011-11-21 15:46:16 EST
Given Felipe gave his OK for the new window.require method I have landed the patch.

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=bccd9ec7b7eacf87d27015a9d78af4f0cfa29487

I hope this is fine with you. Thank you very much!
Comment 7 Felipe Heidrich CLA 2011-11-21 15:54:11 EST
> I hope this is fine with you. Thank you very much!

Yes, thank you.