Writing Modules - nrabinowitz/awld-js GitHub Wiki

Modules will extend the base Module class. Everything in the interface except name is optional, and will be filled with reasonable defaults.

Module interface

  • name_:String_ - Display name for module

  • type_:String_ - Default type for module resources (see types.js for possible types)

  • dataType_:String_ - $.ajax dataType option, to help with parsing and content negotiation (default: json)

  • toDataUri(uri)_:Function_ - Translate HTML URI to a data URI for a particular resource (default: same)

  • noFetch_:Boolean:_ - If set, no remote resources will be fetched for this module (default: false)

  • corsEnabled_:Boolean:_ - Whether the service is CORS-enabled. If not set, a YQL-based proxy will be used for non-JSONP resources.

  • parseData(data)_:Function_ - Translate resource data to a clean data object (default: same)

  • getType(data)_:Function_ - Get the type of a resource based on resource data (default: no-op)

  • detailView(resource)_:Function_ - Make HTML for the detail view (shown in popup) of a given resource (default: ui.detailView)

  • initialize: Function - Additional module initialization (default: no-op)

Development process for new modules

  • Fork the project.

  • Add a new folder for your module(s) to src/modules. The folder provides the namespace for your modules.

  • Create your modules. Modules should follow the Require.js Asynchronous Module Definition (AMD) API, i.e. a function, wrapped in a define() call, with optional dependencies. Dependencies might include one or more library dependencies; in particular, jQuery and Mustache will already be loaded and can be accessed with "jquery" and "mustache", respectively.

  • Your module should return an object that will extend the base Module class. At minimum, it should have a name property. A basic module shell might look like this:

      define(function() {
          return {
              name: 'My Module',
              type: 'place',
              toDataUri: function(uri) {
                  // TODO: Return a mapped data URI
              }
              parseData: function() {
                  // TODO: Return parsed data
              }
          }
      });
    
  • Add your module to the module registry at src/registry.js.

  • Add any 3rd-party library dependencies to src/lib, so that other modules can use them as well.

  • Submit a pull request, and we'll check it out!