You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

npmvc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npmvc

PureMVC for node.js

1.0.2
Source
npmnpm
Version published
Weekly downloads
42
-12.5%
Maintainers
1
Weekly downloads
 
Created
Source

Modification of the multicore javascript port for use in a node.js environment.

This is the npm repo npmvc -> short for node-puremvc. I needed a short name because it is the main dependecies for other modules that are build on this module.

#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");

// make instance of ApplicationFacade and trigger start command
var app = new test.ApplicationFacade();
app.start();

console.log(test);
console.log(puremvc.define);

#Creating external class files

module.exports = function(include,puremvc) {

// use include te aquire dependencies
include("controller/StartCommand");

// ---> now just use puremvc.define to define class
/**
 * @class test.ApplicationFacade
 * @extends puremvc.Facade
 */
puremvc.define(
	{
		name: 'test.ApplicationFacade',
		parent: puremvc.Facade
	},
	{
		/**
		 * @method start
		 * @return {[type]} [description]
		 */
		start: function() {

			this.registerCommand("START", test.controller.StartCommand);
			this.sendNotification("START", {});
		}
	},
	{
		/**
		 * Retrieve an instance of ApplicationFacade. If one has not yet been
		 * instantiated, one will be created for you.
		 *
		 * @static
		 * @param {string} multitonKey
		 * @return test.ApplicationFacade
		 */
		getInstance: function(multitonKey) {
			// all Facade instances, including Facade subclass instances, are stored
			// on Facade.instanceMap. When implementing you own #getInstance factory
			// method, ensure that follow the general pattern implemented here or else
			// puremvc.Facade#hasCore and puremvc.Facade#removeCore will not work if
			// you ever need to use them.
			var instanceMap = puremvc.Facade.instanceMap;
			instance = instanceMap[multitonKey]; // read from the instance map

			if (instance) // if there is an instance...
				return instance; // return it

			// otherwise create a new instance and cache it on Facade.instanceMap;	
			return instanceMap[multitonKey] = new test.ApplicationFacade(multitonKey);
		},

		/**
		 * @static
		 * @type {string}
		 */
		NAME: 'test.ApplicationFacade'
	})
};

#Extra methods: This module adds three exra methods to 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 sourceDir

Keywords

puremvc

FAQs

Package last updated on 18 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts