org.apache.tapestry5.services.javascript

## Class AMDWrapper

- java.lang.Object
- - org.apache.tapestry5.services.javascript.AMDWrapper

-     public class AMDWrapper
      extends 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 calling `require("jQuery", "$")` on the respective wrapper.
  Since:
    5.4
  See Also:
    `JavaScriptModuleConfiguration`, `ModuleManager`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AMDWrapper(Resource resource)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JavaScriptModuleConfiguration` | `asJavaScriptModuleConfiguration()` Return this wrapper instance as a `JavaScriptModuleConfiguration`, so it can be contributed to the `ModuleManager`'s configuration.
    `AMDWrapper` | `require(String moduleName)` Add a dependency on another module.
    `AMDWrapper` | `require(String moduleName, String parameterName)` Add a dependency on another module.
    `AMDWrapper` | `setReturnExpression(String returnExpression)` Optionally sets a return expression for this module.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AMDWrapper

          public AMDWrapper(Resource resource)

  - ### Method Detail

    - #### require

          public AMDWrapper require(String moduleName,
                                    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(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(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 a `JavaScriptModuleConfiguration`, so it can be contributed to the `ModuleManager`'s configuration. The resulting `JavaScriptModuleConfiguration` should not be changed.
      Returns:
        a `JavaScriptModuleConfiguration` for this AMD wrapper

${project.version} - Copyright © 2003-2015 The Apache Software Foundation.