Readlebee/app/views/controller.js

18 lines
642 B
JavaScript
Raw Normal View History

export class ViewController {
constructor(state, i18n, viewName, defaultState = {}) {
// Store the global app state so it's accessible but out of the way.
this.appState = state;
this.i18n = i18n;
this.i18n.__ = this.i18n.__.bind(i18n); // Allow pulling out just the `__` function for shortened translation declaration.
// 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;
}
}