src/Application/Application.ts   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 53
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 53
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1
wmc 7
mnd 2
bc 2
fnc 5
bpm 0.4
cpm 1.4
noi 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A Application.attachToModuleState 0 3 1
A Application.attachToMenuOpenState 0 3 1
A Application.attachToLanguage 0 3 1
A Application.attachToContainerNode 0 4 2
A Application.run 0 6 2
1
import {PageData} from '@enbock/application-router/Router';
2
import ListenerAdapter from '@enbock/state-value-observer/ListenerAdapter';
3
import {ObserverAdapter} from '@enbock/state-value-observer/ValueObserver';
4
import React from 'react';
5
import ApplicationView, {Adapter as ViewAdapter} from './View/Application';
6
import Model from './View/Application/Model';
7
import ApplicationPresenter from './View/Application/Presenter';
8
9
export interface ModulePageData extends PageData {
10
  module: string
11
}
12
13
export interface Adapter extends ViewAdapter {
14
  onPageChanged(newValue: PageData | null): void;
15
}
16
17
export default class Application {
18
  private readonly adapter: Adapter;
19
  private readonly presenter: ApplicationPresenter;
20
  private view: ApplicationView | undefined;
21
  private readonly runCallback: () => void;
22
23
  constructor(adapter: Adapter, presenter: ApplicationPresenter) {
24 6
    this.presenter = presenter;
25 6
    this.adapter = adapter;
26 6
    this.runCallback = this.run.bind(this);
27
  }
28
29
  attachToLanguage(adapter: ListenerAdapter<string>) {
30 6
    adapter.addListener(this.runCallback);
31
  }
32
33
  attachToModuleState(adapter: ListenerAdapter<typeof React.Component | null>) {
34 6
    adapter.addListener(this.runCallback);
35
  }
36
37
  attachToMenuOpenState(adapter: ObserverAdapter<boolean>) {
38 6
    adapter.onChange = this.runCallback;
39
  }
40
41
  attachToContainerNode(containerNode: Element | DocumentFragment | null) {
42 5
    if (containerNode == null) return;
43 4
    this.view = new ApplicationView(containerNode, this.adapter);
44
  }
45
46
  run() {
47 7
    if (this.view == undefined) return;
48
49 4
    const model: Model = this.presenter.present();
50 4
    this.view.render(model);
51
  }
52
}
53