@wider/registry

A framework for all $wider bundles but also a tracker for different modules of the same name being loaded by different packages of the same

creates

global.$wider = { 
    // container for other wider globals
}

Classes

loggedError

Methods

inner bundle(entries, sectionopt) → {Dictionary}

Merge one or more objects that do not register themselves, for example because they are a third party package

Care needs to be taken when you act as proxy to register other packages in case different parts of your solution try to register the same third party package. If the risks remain despite your care, check in global.$wider before calling register.

Parameters:
Name Type Attributes Description
entries Array | Object

A single object will be treated as if it were the first member of an Array. The array is a collection of objects, each to be registered individually. Each object must contain the property $moduleName, and optionally may contain $objectName, both as defined in registry.register(). If you are registering as proxy, you will need to add these properties to each object before registering them.

If .$moduleName or .$objectName are missing, an attempted will be made to generate these and an error will be thrown if usable values cannot be created.

section NCName <optional>

if provided then the name of the section where the entries are to be lodged

Throws:

if any of the modules self registers or if it has not been possible to determine valid moduleName or objectName for any of the modules

Type
loggedError
Returns:
Dictionary -

the $wider object that has been extended by the given entries

inner defer(entries, sectionopt)

Allow you to include large numbers of rarely used modules in your $wider object on a deferred loading scheme, so that your app's start up and run time does get filled with wasteful bloat. Your entries appear in $wider. Used exactly as .bundle{}, entries appear in $wider and are used in the same way. The only difference is that the module is not loaded/required unless and until it is actually used. Loading is always synchronous so as to honour your existing code without change and occurs just in time and will occur if you destructure the item from $wider or refer to it directly.

As with other items in the registry, you may only load a given module once, but you can change your program to place items either in bundle() and defer(). Apart from changing the timing of loading into memory, there is no other impact.

You can put .merge() items within a defer() object but that will have the effect of un-deferring the object.

When debugging, viewing the container of the deferral, this will cause the all deferrals to be loaded/required.

If a module does not self register, then this function will register it for you.

Parameters:
Name Type Attributes Description
entries Array

one entry for each member whose loading is to be deferred until the first time of use. Each entry may be either a string module name or an object containing at least the .$moduleName property and optionally .$objectName. $moduleName that are relative paths are not supported, if from local files always used resolved paths. Other properties of the object are ignored

section NCName <optional>

if provided then the name of the section where the entries are to be lodged

inner find(moduleName) → {*}

Relate the given moduleName to the entry in $wider

Parameters:
Name Type Description
moduleName String

the module name to be found

Returns:
* -

the result of the search being undefined if the moduleName is unknown, or the element within $wider that was registered with the given moduleName

inner loaded() → {String}

Generate a report of the items that have been loaded and how long into the run session it was when they are loaded. NB not all loaded items are published.

Returns:
String -

a tabular report of items loaded

inner merge(moduleNameopt, entries, mergeIdopt) → {Dictionary}

Merges designated properties in a pre-existing registered object. Often used to add CONSTANTS or CONFIG values to an existing container

Parameters:
Name Type Attributes Description
moduleName String <optional>

as per registry.register() - if the name is null, then the entries are added at the root of $wider or the section if provided

entries Dictionary

properties and methods to be added to the named $moduleName

mergeId NCName <optional>

optional name of the merge for documentary purposes

Throws:

if either the existing module does not exist or if you try to revise an entry that already exists

Type
loggedError
Returns:
Dictionary -

the $wider object that has been extended by the given entries

inner published() → {String}

A report of the structure in the object that is published via the common object

Returns:
String -

a tabular report of items published

inner register(moduleNameopt, valueopt, objectNameopt, sectionopt) → {Dictionary}

Registers an object typically as it is being constructed via require or import. The purpose being to ensure that multiple packages within your runtime on a given cluster do not load the same module more than once - as can happen when a package is a dependency of several other packages. This function should only only be called from within the module level code of the module that is registering itself

Parameters:
Name Type Attributes Description
moduleName String <optional>

the name of the item to be registered. The string should be the same as used as might be used as id in require or import, or as used in npm install

If moduleName is an object it is treated as a dictionary of registrations where the keyName is the moduleName and the associated value is an object with the properties value and objectName. It may also contain ***section^^^ which if present will override the section parameter of the call to .register()

If moduleName is absent then nothing is registered and the only action is to return the output Dictionary bundle

value * <optional>

if present then the moduleName must be supplied and this value is added to the bundle.

If absent, then the moduleName, if provided, is registered in the dictionary and nothing is added to the bundle.

If this is an object (class, function, json, plain object) then it should have a $moduleName static property which is the same as the parameter moduleName. It may also have a property $objectName

  • if this is a string then it must be the same as the objectName in this request
  • if this is the value of registry.MERGE then moduleName must already have been registered and the value shall be a dictionary of entries according to section, none of which may pre-exist
objectName NCName <optional>

if objectName is present, then value must be supplied and the value is stored in the response of this @wider/registry response under this name available for direct use by any other module without use of require or import. If objectName is not provided then it will be assumed to be the same as moduleName

section NCName <optional>

if absent then the value is saved under objectName at the top level of the output Dictionary, otherwise this defines the section name in the dictionary under which the value is filed

Throws:

an extension of the javascript `Error`` object. It is thrown when a registration is rejected

Type
loggedError
Returns:
Dictionary -

containing all registered items under their objectname and section.