Module Management - Part 1 - getModule() Pattern
As discussed in Module Management - Analysis, EA does not provide support for the ubiquitous Module Pattern. This becomes an issue with an increase in complexity of model addins. In order to a) Minimise the management of dependencies, and b) Cater for the use of 3rd party modules, The framework provides an analogous pattern, which I'm calling the getModule() pattern, because I lack imagination.
The premise is straight forward. Rather than having an anonymous self executing function returning a module object, we instead have module class elements which have a method called "getModule()" and this returns a module object when the method is called.
The getModule() method would be declared (via the EA interface) on a class element, and then we would place all of the module's code in the body of the getModule() method/operation. The method would return a module object to the caller.
The sample contents of a typical getModule() operation might look like this.
The premise is straight forward. Rather than having an anonymous self executing function returning a module object, we instead have module class elements which have a method called "getModule()" and this returns a module object when the method is called.
The getModule() method would be declared (via the EA interface) on a class element, and then we would place all of the module's code in the body of the getModule() method/operation. The method would return a module object to the caller.
The sample contents of a typical getModule() operation might look like this.
var prompt = '> '; function setPromptInternal(newPrompt) { prompt = newPrompt; } function outputInternal(output) { dbg(prompt + output); } var module = {}; module.setPrompt = setPromptInternal; module.output = outputInternal; return module;
Higher level code, either the JavascriptAddin element or an intermediate object can then do the following to access the module code.
var instance = new the_module_element(); var module = instance.getModule(); module.setPrompt('bob >'); module.output('hello'); // Outputs 'bob > hello'
It is granted that the above code is messy looking. And hence, in order to make this easier to work with a global object called "namespace" has been created to manage namespaces and to make use of the getModule() pattern easier. The use of the namespace object allows code of the following form.
namespace.include(ser_ea_context); namespace.include(ser_external_log4js, {useNamespace: 'ser.external.log4js});
I will cover the naming standard used in the framework and the use of the namespace object in greater detail in the next few posts.
Comments
Post a Comment