#PureMVC for node.js
###Modification of the multicore javascript port for use in a node.js environment.
This is the master repository of the npm npmvc
module.
The main goal of this module is to add more flexibility and modulairity within the use of the combination of Node.js and the PureMVC framework. The module enables the aggregation of classes in a local file structure of PureMVC classes or in seperated modules.
It adds an include
method on top of the official multicore PureMVC JavaScript library (currently version 1.0.1). This method is based on the node.js require
method and is added to the puremvc namespace. (See API specs below).
You can use the include
function to include dependecies that are located local or in other npm modules. Class files are wrapped the node.js module.export style (see Creating external class files).
#install
npm install npmvc
#setup a puremvc project in node.js
When installed you can use it like this
var puremvc = require("npmvc");
puremvc.setSourceDir(__dirname+"/src");
puremvc.include("AppConstants");
puremvc.include("ApplicationFacade");
var app = new test.ApplicationFacade();
app.start();
console.log(test);
console.log(puremvc.define);
#Creating external class files
module.exports = function(include,puremvc) {
include("controller/StartCommand");
puremvc.define(
{
name: 'test.ApplicationFacade',
parent: puremvc.Facade
},
{
start: function() {
this.registerCommand("START", test.controller.StartCommand);
this.sendNotification("START", {});
}
},
{
getInstance: function(multitonKey) {
var instanceMap = puremvc.Facade.instanceMap;
instance = instanceMap[multitonKey];
if (instance)
return instance;
return instanceMap[multitonKey] = new test.ApplicationFacade(multitonKey);
},
NAME: 'test.ApplicationFacade'
})
};
#Extra methods:
This module adds some exra methods on top of the puremvc
root object:
##puremvc.setSourceDir(path:string):void
path [string] Sets the source dir for all include's, It uses this for includes on all directory levels. So when you include a dependencie in say model/MyProxy
you have to reference model/vo/MyVo
by using the path up from the sourceDir, not relative to the folder the file is in:
puremvc.include("model/vo/MyVo");
If you have to hack this, you can use tempPath, the second param of puremvc.include. See below.
Also not that if you do not set the sourceDir it will default to process.cwd()
(the directory where you started the main node file).
##puremvc.include(path:String, tempPath:String, callback:function):*
Returns any value, but mainly use for return the reference to the classlets constructor from pure.define.
path [string]
Path to puremvc class, relative from path set by puremvc.setSourceDir
tempPath [String]
This overides the sourceDir. A include of MyVo
in class model/vo/MyVo
would look like this:
puremvc.include("vo/MyVo",__dirname);
callback [function]
You can use an callback, but you have to trigger it in the aquired class file.
You can include a class in an other npm module if the file is not equal in the context of your current sourceDir path. So when you want to load the class SomeClass
in the module my-npm-module
then do not use tempPath but use:
puremvc.include("my-npm-module/path/to/SomeClass");
##puremvc.getSourceDir():string
returns the current source directory, root of puremvc classes.