partial.js logo
Latest version
v1.3.1 (RC2)

How do modules work?


Modules serve for simplification of work on a project. You can use module in other projects.



Starting partial.js project

Download modulesModule example


Module definition


// Module name: test
exports.install = function(framework, name) {

	// Initialize function (is executed automatically one time)

}

exports.myFunction = function(name) {
	return name;
}

exports.myProperty = 'Property';

Get values from modules



	console.log(framework.module('test').myFunction('Peter'));
	console.log(framework.module('test').myProperty);

	console.log(controller.module('test').myFunction('Peter'));
	console.log(controller.module('test').myProperty);


Monitoring modules


partial.js supports monitoring of modules via module usage. Usage example.

var counter = 0;

exports.install = function(framework, name) {
	framework.route('/module/', view_module);
};

exports.usage = function() {
	return 'Visits: ' + counter;
};

function view_module() {
	// this === controller
	counter++;
	this.plain('Module response.');
}

Global module


The global module is run as last and its name must be #.js. In global module you can define additional
functions (similarly as definition).