v1.1

AppOne

The one route i.e. one controller app. Use this class to start an application that doesn't require routing, such as a browser extension.

class AppOne → AppOne.js

Instance

To start the app create an object instance.
const appOne = new AppOne(appName);

Properties

The appOne instance properties are:
Property Description Type Default
$appName The application name. It defines the window property. For example if $appName='myApp' then window.myApp string dodoApp
$debugOpts Debugger options. Set specific option to true if you want to see the debugging messages. See all options. object {...}
ctrls A collection of all controllers. This makes possible to use a controller's methods inside another controller. object {}
ctrlConstants A controller constants which will not be deleted when one controller is replaced by another controller (when route is changed).
{$appName, $fridge, $httpClient, $auth, $debugOpts, $model, $modeler, $dd}
object {...}

Methods

httpClient($httpClient) :AppOne

Set the $httpClient property in all controllers. It can be called with this.$httpClient in the controller.
The HTTP client is used for certain API calls.
    ARGUMENTS:
  • $httpClient :object - the http client object
EXAMPLE:
An app needs HTTP client in the controllers to fetch the JSON from API.

// src/const/$httpClient.js
=========================
import { corelib } from '@mikosoft/dodo';

// default HTTP client
const opts = {
  encodeURI: true,
  timeout: 21000,
  responseType: '', // 'blob' for file download (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType)
  retry: 0,
  retryDelay: 1300,
  maxRedirects: 0,
  headers: {}
};
const $httpClient = new corelib.HTTPClient(opts);

export default $httpClient;


// src/app.js
=========================
import { AppOne } from '@mikosoft/dodo';
import $httpClient from './conf/httpClient.js';
import SomeCtrl from './controllers/SomeCtrl.js';
const appOne = new AppOne('myApp');
appOne
    .httpClient($httpClient)
    .controller(SomeCtrl);
Now this.$httpClient is injected in the controller and can be used to call the API.
// src/controllers/SomeCtrl.js
=============================
import { Controller } from '@mikosoft/dodo';

export default class SomeCtrl extends Controller {
  async __init() {
    const answer = await this.$httpClient.askJSON('https://jsonplaceholder.typicode.com/posts/1');
  }
}

debug($debugOpts) :AppOne

Set the debug options.
EXAMPLE:
import { $httpClient, $debugOpts } from './conf/index.js';
const appOne = new AppOne('myApp');
appOne
  .httpClient($httpClient)
  .debug($debugOpts)
  .controller(SomeCtrl);

i18n($i18n) :AppOne

Set the global window.<appName>.i18n property, which is used in the View.loadI18n(langCode) method.
The language object $i18n can be loaded from various sources such as databases, files, browser storage, etc.
It is not saved in the controller object to keep it as small as possible. The language $i18n object can be large and significantly increase the size of the controller object.
    ARGUMENTS:
  • $i18n :object - object with language translations, for example {de: {common: {USERNAME: 'Nutzername'}, home: {TITLE: 'Startseite', LOGIN: 'Anmeldung'}}}

controller(Ctrl) :void

Define and execute the app's controller. This will be the sole controller used in the application.
In App.js, this is equivalent to the `route()` and `listen()` methods.
    ARGUMENTS:
  • Ctrl :Class - the controller class
EXAMPLE:
This is the simplest example
import HomeCtrl from './controllers/HomeCtrl.js';
const appOne = new AppOne('myAppOne');
appOne.controller(HomeCtrl); // execute the home controller