2019-09-07 21:54:44 +02:00
|
|
|
export class ViewController {
|
2019-09-16 20:32:53 +02:00
|
|
|
constructor(state, i18n, viewName, defaultState = {}) {
|
2019-09-07 21:54:44 +02:00
|
|
|
// Store the global app state so it's accessible but out of the way.
|
|
|
|
this.appState = state;
|
2019-09-16 20:32:53 +02:00
|
|
|
this.i18n = i18n;
|
|
|
|
this.i18n.__ = this.i18n.__.bind(i18n); // Allow pulling out just the `__` function for shortened translation declaration.
|
2019-09-07 21:54:44 +02:00
|
|
|
|
|
|
|
// Give this view its own state within the appState.
|
|
|
|
if (!this.appState.viewStates.hasOwnProperty(viewName)) {
|
|
|
|
this.appState.viewStates[viewName] = defaultState;
|
|
|
|
}
|
|
|
|
this.state = this.appState.viewStates[viewName];
|
|
|
|
}
|
2019-09-14 06:41:16 +02:00
|
|
|
|
|
|
|
get isLoggedIn () {
|
|
|
|
return this.appState.isLoggedIn;
|
|
|
|
}
|
2019-09-07 21:54:44 +02:00
|
|
|
}
|