>>   - I'm using "require" to get classes available to the program, but are 

>Is this the Node.js' built-in 'require'?! 

yes. require('./this/that');



>> relative from where I need them so I have to take care that it's the
>> right 
>> way to require them every time. I have to repeat things: once in the
>> require 
>> and the other when I use the code; 

>What do you mean? Can you give an example of these two uses? 

"relative from where I need them so I have to take care that it's the right
way to require them every time."
here I mean: if I have a app structure like this:
root
 |-file3.js <-- I'm here (1)
 |-folder1
 |-folder2
    |-file1.js <-- I want this
    |-file2.js <-- I'm here (2)

If I want file1 from file3 the require would be:
require('./folder2/file1');

If I want file1 from file2 the require would be:
require('./file1');

And this is quite painful because then I would have to repeat this whenever
I would need them too.
"I have to repeat things: once in the require and the other when I use the
code"
My code would look:

require('./file1');
// ...
var a = new folder2.file1();

Here is quite bad design I think and could lead to more errors and of course
repetition of code.

Here I begin to think that it's better to use the "node_modules" way so I
could make my code like this, which is quite better:

require('folder2/file1');
// ...
var a = new folder2.file1();



----------------------------
Which problem are you trying to solve here? You're not aiming at getting 
rid of code like 

   var a = new qx.core.Aspect() 

, do you? As this would be breaking a lot of qooxdoo code. 

You probably want to get rid of the corrsponding 'require' call 
(something like 'require("qx/core/Aspect.js")')?! That's very sensible, 
but you wouldn't need an entirely new qx.Class.define, would you?! And 
you wouldn't want to declare all your dependencies, too. That's what the 
generator is for. So a good solution for me would be that the generator 
extracts all dependencies, generates the corresponding 'require' calls, 
and wraps this code in front of your class definition. 
----------------------------
Well this can be solved in 2 ways:
1) use a generator for the server side: this would solve all problems, but I
don't know the level time and effort of doing this and if it's worth.
or
2) declare dependencies and change some code in the qx.Class.define, that's
why it's more painful, but that would solve some problems too: we can run
server side code without generating and using require in node js. This could
also be used in the client side too...




----------------------------
This would be on a per-file basis. The generator is already doing 
something similar, but on a file-set basis, in the current loader. So if 
you e.g. use the 'basic' skeleton, the generator will create a loader 
that handles all 'require's for you. 
----------------------------
Are you talking for the server side? how could I do it?




----------------------------
So from what I understood this is how it could be done to share code to the
client, please correct me if I'm wrong:

First use the node_modules to keep javascript code.
I have my modules here "C:\Users\Totty\node_modules";
Should I create here a new folder and name it as the project name?
Here I will put all my classes of qooxdoo, right? 
then this folder will be included in the build (config.json, manifest) in
order to be able to use them on the client side?
I keep those files as a library?

So I create a folder named "my_project" as the main project;
Then in the "C:\projects\my_project" (where I keep my projects) I use:

Here I use the library made before...
a) require from nodejs
b) or the generator can handle it? How should I config?

thanks a lot for your answer (:

--
View this message in context: 
http://qooxdoo.678.n2.nabble.com/Reusing-server-side-code-in-the-client-side-how-to-get-rid-of-the-require-in-nodejs-suggestion-tp7452919p7456019.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to