JonFerraiolo Hub Proposals 2007-02-20

From MemberWiki

Jump to: navigation, search

Contents

About this wiki page

This wiki page describes a set of proposed changes to:

The impetus behind these proposed changes come from things Jon noticed as implementing recently changes within the open source project.

The contents of this wiki page will be discussed at the 21 Feb 07 Interoperability phone call.


Proposed changes

1. Merge Libraries.js and Globals.js (after splitting out Collisions.js) into OpenAjaxBootstrap.js

After the changes we agreed to at our last phone call, Libraries.js and Globals.js are trivial. Here is the code within Libraries.js:

OpenAjax.__moduleLibraries = 1;

// holds the libraries that have been registered so far.
OpenAjax.libraries = {};

/*
 *	Registers an Ajax library with the OpenAjax Hub.
 */
OpenAjax.registerLibrary = function (
		prefix,			// Unique library ID string, suitable as prefix in xmlns declaration
		namespaceURI,   // Namespace URI string suitable for use with xmlns attribute
		version,		// Library version in the form of #[.#]*, such as "1", "1.1" or "1.20.2".
		extraData){		// Optional, can be null. Arbitrary Object holding extra info about library.
	if (this.libraries[prefix]) {
		throw new Error("Repeat attempt to register library: " + prefix);
	}
	this.libraries[prefix] = {
		prefix: prefix,
		namespaceURI: namespaceURI,
		version: version,
		extraData: extraData
	};
};

/*
 *	Unregisters an Ajax library with the OpenAjax Hub.
 */

OpenAjax.unregisterLibrary = function(
		prefix ){			// Library prefix that was passed to registerLibrary().

	// Remove references to any globals registered to this library.
	// (See Globals.js)
	if (this.globals) {
		delete this.globals[prefix];
	}

	// Remove registration for this library.
	delete this.libraries[prefix];
};

// Register the OpenAjax Hub itself as a library.
OpenAjax.registerLibrary("OpenAjax", "http://openajax.org/hub", "0.3", {});

And here is the code for Globals.js:

OpenAjax.__moduleGlobals = 1;

// Hash mapping libraries registered so far to a list of their global object names
OpenAjax.globals = {};

/*
 *	Identifies the global objects that the given Ajax library is adding to
 *	the JavaScript runtime environment.  If any collisions are found,
 *	a runtime error will be raised.
 */
OpenAjax.registerGlobals = function (
		prefix,			// Library prefix that was passed to registerLibrary().
		globals){		// An array of strings that identify the globals added 
						// to the JavaScript runtime environment by this library.
	// Everything is OK, so register the globals for this library.
	this.globals[prefix] = globals;
};

// Register the OpenAjax Hub's globals
OpenAjax.registerGlobals("OpenAjax", ["OpenAjax","OpenAjaxConfig"]);

The above logic is required in all cases, so it doesn't really belong in a "module", so let's merge it into the bootstrap JavaScript file. (Which leads into the next suggestion...)

2. Rename OpenAjaxBootstrap.js to OpenAjaxCore.js. (It clearly does more than bootstrapping now.)

If everyone agrees with #1, then OpenAjaxBootstrap.js is doing more than just bootstrapping. Therefore, let's rename it to OpenAjaxCore.js.

3. Rename globalsCollisionCheck() to checkForCollisions()

This change is very minor and arbitrary, but I think it is an improvement.

Personal tools