Hi guys,

This is my first post here. I am fairly new to node, and very new to 
Javascript although I have been programming for a number of years.
I am writing a framework to write store-based, SaaS applications easily 
using node. In order to do that, I decided to create a system where each 
module would:

* Be initialised
* Be based on hooks/signals -- emitting and subscribing -- to do their job

What I came up with is Hotplate: 
https://github.com/mercmobily/hotplate/blob/master/hotplate.js
Please keep in mind that this is quite preliminary code: function names 
tend to suck, etc. It was also pretty much the first real thing I ever 
wrote in node.

In my server.js file I have something like this:

hotplate.setApp(app)
hotplate.set( 'staticUrlPath', '/hotplate' );     // Set the static URL 
path for all modules
hotplate.set( 'dgrid-theme', 'claro' );

//...

 // Register modules
  hotplate.registerAllEnabledModules('node_modules', /^hotCore/ ); // 
Register all core modules from hotplate's node_modules's dir
  hotplate.registerAllEnabledModules('node_modules', /^hotDojo/ );
  hotplate.registerAllEnabledModules('node_modules', /^hotMongo/ );
  hotplate.initModules( function() {

    app.configure(function(){
//...

registerAllEnabledModules, other than having a name that is too long of its 
own good, will basically:

1) Load those modules
2) Once they are all loaded, will call their init() functions **in the 
right order**.

The part where I write "in the right order" is the most important one.
Take for example the module 'hotCorePage': in its init, it does this:

HotCorePage.prototype.hotHooks.init = function( done ){

  var that = this;

  hotplate.invokeAll('pageElements', function(err, results){
    enrichElementsWithResults( that, results )

    that.pageTemplate = replacePageElements( that.pageTemplate, {
       csses:that.csses,
       jses:that.jses,
       vars:that.vars,
       headLines:that.headLines
    } );

    done( null );

  });
}
HotCorePage.prototype.hotHooks.init.invokes = [ 'pageElements' ];

Note that hotCorePage invokes "pageElements". The point here is that all 
modules providing pageElements will need to be initialised *before* 
hotCorePage, so that their pageElements function can actually work 
properly. Rather than inspecting the function, I declare explicitly what 
hooks an init() function will invoke (see the last line). Any module 
providing those hooks will be initialised _before_ hotCorePage.

The main reason why I am writing here is... well, to:

* get some confirmation that I didn't do anything horrific
* ideas of how this could be done differently (I wouldn't be surprised if 
there was a much easier, much better way of doing all this)
* general feedback

As I mentioned, the code is not yet polished. However, you _can_ create a 
working SaaS, multi-homed, with user registration etc. in less than 5 
minutes using it.

Thanks for listening,

Merc.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to