evantahler/actionhero — pull request #307 by TJKoury (2014-01-24 01:17:24+00:00)
Title: Common loader for initializers

This is the common loader implementation I created for initializers; both action.js and task.js create instances of the ./initializers/common/commonLoader.js object and then modify/add properties/methods as required. This allows the following:

-Common loading pattern for directories
-Common loading pattern for files/modules
-Common initialization pattern
-Common file watching behavior
-Internal validation engine that allows for name/type pairs to be used, with the option of rolling it into additional wrapper validation logic that is initializer specific (see action.js for example)

I also cleaned up the differences in method/property declaration between the two initializers. I removed the object literal notation in tasks.js, makes it easier to inherit/override from an instantiated object instead of having to rewrite everything using a common prototype. Usually prototypical inheritance is a good thing; here though, using the visitor pattern and passing around 'api' seems to be the way to go, so having to redirect references up the prototype chain could result in 'apparent' non-deterministic behavior depending on the state of api when any given method is analyzed, or at the very least be confusing enough that debugging becomes unfeasible.