Skip to content

Modules

philipeachille edited this page Mar 27, 2020 · 9 revisions

Introduction

All code is structured using the "Model View Presenter" design pattern, wrapped into modules that follow the "Revealing Module Pattern". Below is an example for the basic structure of a module, as used a lot in the code base.

Example

const SomeModule = ( function() {

  /**
   * Module to do something
   *
   */

  'use strict';

  const someVariable = 'whatever';

  /* ================== private methods ================= */

  function doSomethingOnAppLaunch() {
    // do something here, for example also using someVariable
  }

  function presenter( which, options ) {
    // get some data and/or component according to the 'which' parameter, mash it into usable stuff considering the options parameter, and send it to the view

    return {
      someStuff: someStuff,
    };

  }

  function view( stuff ) {
    // do something with the stuff, like updating the DOM
  }

  /* ============ public methods and exports ============ */

  function launch() {
    doSomethingOnAppLaunch();
  }

  function draw( options ) {
    view( presenter( which, options ) );
  }

  return {
    launch: launch,
    draw: draw,
  };

} )();
Clone this wiki locally