FAQ
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
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 nodejs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Tony Mobily at Mar 30, 2013 at 1:23 am
    Hi,

    I guess my question/issue was out of place here -- sorry about the noise!

    Merc.
    On Thursday, March 28, 2013 1:02:30 PM UTC+8, Tony Mobily wrote:

    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    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 nodejs+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Tony Mobily at Oct 31, 2013 at 6:05 am
    Hi,

    Answering to myself. My whole idea of running init functions in the right
    order was absolute insanity, and -- worse of all -- re-invented a wheel
    that already existed (node's own module management).

    So... well, I scrapped it
    https://github.com/mercmobily/hotplate/commit/81916c969e0cb0e7af62abb352143a084823851f .
    Now I basically make sure that there is no "order requirement" in my
    module, got rid of the (silly) custom module loader, and in the meantime
    wrote (quickly) https://github.com/mercmobily/EventEmitterCollector which
    allows you to emit() an event, and collect the (async) results from the
    listeners.

    Just for posterity, I suppose.

    Merc.


    On Saturday, March 30, 2013 9:23:08 AM UTC+8, Tony Mobily wrote:

    Hi,

    I guess my question/issue was out of place here -- sorry about the noise!

    Merc.
    On Thursday, March 28, 2013 1:02:30 PM UTC+8, Tony Mobily wrote:

    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    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 nodejs+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedMar 28, '13 at 12:42p
activeOct 31, '13 at 6:05a
posts3
users1
websitenodejs.org
irc#node.js

1 user in discussion

Tony Mobily: 3 posts

People

Translate

site design / logo © 2021 Grokbase