helpers/jrequire

Service locator to make module dependencies more flexible.. The basic idea is that for a framework, one wants to be able to decouple dependencies so that one could swap in a replacement module easily. For example, imagine a framework with different classes for users, resources, etc., which are tightly coupled and co-dependent, where one would like to use the framework but swap out a class for a replacement (derived) class. The approach here is to use a singleton centralized registry of modules used by a framework, and allow an initial setup to change the mappings from names to modules. Use as a replacement for require, after modules/paths have been registered. This is meant to be used as a singleton -- a global central requirement loader for our classes. It is only meant to be used for modules that one might want to swap out with replacements when using a given framework.

Source:
Author:
See:

Methods

(inner) calcDebugInfo()

Source:

Just return an object with debugging information suitable for display

Returns:

debug object with info on named and paths

(inner) fixRequirePath(path)

Source:

Private function that we could use to do some special replacements, like replacing %APPROOT% with root path of project, etc.

Parameters:
Name Type Description
path string
Returns:

path with any special replacements

(inner) jrequire(name)

Source:

Substitute for the normal cached require() statement

Parameters:
Name Type Description
name string

name used to register previously

Returns:

result of previous require statement

(inner) registerPath(name, requirePath)

Source:

Register a new module dependency by its path.

Examples
jrequire.registerPath("helper", require.path("accessories/helper"));
jrequire.registerPath("coremod", "coremodule"); // where require(path) will resolve
Parameters:
Name Type Description
name string

the same to store the requirement under (can include / . etc)

requirePath string

full path to pass to the require module

Notes
  • the requirePath can be a full path obtained via require.resolve() OR a path relative to where the jrequire.js module is, OR an npm registered module (might be useful for npm registered plugins)

(inner) registerRequire(name, requireResult)

Source:

Register a new module dependency by directly passing in the result of require()

Example
jrequire.registerRequire("helper", require("accessories/helper"));
Parameters:
Name Type Description
name string

the same to store the requirement under (can include / . etc)

requireResult object

result of a require statement on a module

(inner) setDeferredLoading(val)

Source:

Set the deferred loading flag

Parameters:
Name Type Description
val boolean