Class AMDWrapper
- java.lang.Object
-
- org.apache.tapestry5.services.javascript.AMDWrapper
-
public class AMDWrapper extends java.lang.Object
Used to wrap plain JavaScript libraries as AMD modules. The underlying resource is transformed before it is sent to the client. This is an alternative to configuring RequireJS module shims for the libraries. As opposed to shimmed libraries, the modules created using the AMDWrapper can be added to JavaScript stacks. If the library depends on global variables, these can be added as module dependencies. For a library that expects jQuery to be available as$
, the wrapper should be setup callingrequire("jQuery", "$")
on the respective wrapper.- Since:
- 5.4
- See Also:
JavaScriptModuleConfiguration
,ModuleManager
-
-
Constructor Summary
Constructors Constructor Description AMDWrapper(Resource resource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaScriptModuleConfiguration
asJavaScriptModuleConfiguration()
Return this wrapper instance as aJavaScriptModuleConfiguration
, so it can be contributed to theModuleManager
's configuration.AMDWrapper
require(java.lang.String moduleName)
Add a dependency on another module.AMDWrapper
require(java.lang.String moduleName, java.lang.String parameterName)
Add a dependency on another module.AMDWrapper
setReturnExpression(java.lang.String returnExpression)
Optionally sets a return expression for this module.
-
-
-
Constructor Detail
-
AMDWrapper
public AMDWrapper(Resource resource)
-
-
Method Detail
-
require
public AMDWrapper require(java.lang.String moduleName, java.lang.String parameterName)
Add a dependency on another module. The module will be passed into the generated factory function as a parameter.- Parameters:
moduleName
- the name of the required module, e.g.jQuery
parameterName
- the module's corresponding parameter name of the factory function, e.g.$
- Returns:
- this AMDWrapper for further configuration
-
require
public AMDWrapper require(java.lang.String moduleName)
Add a dependency on another module. The module will be loaded but not passed to the factory function. This is useful for dependencies on other modules that do not actually return a value.- Parameters:
moduleName
- the name of the required module, e.g.bootstrap/transition
- Returns:
- this AMDWrapper for further configuration
-
setReturnExpression
public AMDWrapper setReturnExpression(java.lang.String returnExpression)
Optionally sets a return expression for this module. If the underlying library creates a global variable, this is usually what is returned here.- Parameters:
returnExpression
- the expression that is returned from this module (e.g.Raphael
)- Returns:
- this AMDWrapper for further configuration
-
asJavaScriptModuleConfiguration
public JavaScriptModuleConfiguration asJavaScriptModuleConfiguration()
Return this wrapper instance as aJavaScriptModuleConfiguration
, so it can be contributed to theModuleManager
's configuration. The resultingJavaScriptModuleConfiguration
should not be changed.- Returns:
- a
JavaScriptModuleConfiguration
for this AMD wrapper
-
-