UNPKG

1.54 kBJavaScriptView Raw
1import ReactDOM from 'react-dom';
2import React from 'react'; //eslint-disable-line no-unused-vars
3
4export class BaseController {
5 constructor(routeContext, view = null) {
6 this.routeContext = routeContext;
7 this._view = view;
8 this._viewInstance = null;
9 }
10
11 set view(value) {
12 this._view = value;
13 }
14
15 get view() {
16 return this._view;
17 }
18
19 get viewInstance() {
20 return this._viewInstance;
21 }
22
23 static get loginRequired() {
24 return true;
25 }
26
27 render(context = {}) {
28 var View = this._view; //eslint-disable-line no-unused-vars
29 context.currentState = this.routeContext.currentState;
30 this._viewInstance = ReactDOM.render(<View {...context} controller={this} />, this.routeContext.element);
31 }
32}
33
34export class BaseLayoutController extends BaseController {
35 // in base layout view
36 // layout view correspond to BaseController view
37 // and view correspond to the view to set in content property
38 constructor(routeContext, view = null, layoutView = null) {
39 super(routeContext, layoutView);
40 this._contentView = view;
41 }
42
43 set layoutView(value) {
44 this._view = value;
45 }
46 get layoutView() {
47 return this._view;
48 }
49
50 set view(value) {
51 this._contentView = value;
52 }
53 get view() {
54 return this._contentView;
55 }
56
57 get viewInstance() {
58 return super.viewInstance.refs.contentView;
59 }
60
61 render(context = {}) {
62 var mergedContext = {};
63 mergedContext.contentProps = context;
64 mergedContext.content = this._contentView;
65 super.render(mergedContext);
66 }
67}
68
\No newline at end of file