correctly pass options to ViewModel ctor
This commit is contained in:
parent
0eefc88fe3
commit
b0e59c30dd
4 changed files with 27 additions and 10 deletions
|
@ -4,12 +4,12 @@ import {SessionPickerViewModel} from "./SessionPickerViewModel.js";
|
||||||
import {ViewModel} from "./ViewModel.js";
|
import {ViewModel} from "./ViewModel.js";
|
||||||
|
|
||||||
export class BrawlViewModel extends ViewModel {
|
export class BrawlViewModel extends ViewModel {
|
||||||
constructor({createSessionContainer, sessionInfoStorage, storageFactory, clock}) {
|
constructor(options) {
|
||||||
super();
|
super(options);
|
||||||
|
const {createSessionContainer, sessionInfoStorage, storageFactory} = options;
|
||||||
this._createSessionContainer = createSessionContainer;
|
this._createSessionContainer = createSessionContainer;
|
||||||
this._sessionInfoStorage = sessionInfoStorage;
|
this._sessionInfoStorage = sessionInfoStorage;
|
||||||
this._storageFactory = storageFactory;
|
this._storageFactory = storageFactory;
|
||||||
this._clock = clock;
|
|
||||||
|
|
||||||
this._error = null;
|
this._error = null;
|
||||||
this._sessionViewModel = null;
|
this._sessionViewModel = null;
|
||||||
|
|
|
@ -3,8 +3,9 @@ import {SyncStatus} from "../matrix/Sync.js";
|
||||||
import {ViewModel} from "./ViewModel.js";
|
import {ViewModel} from "./ViewModel.js";
|
||||||
|
|
||||||
export class SessionLoadViewModel extends ViewModel {
|
export class SessionLoadViewModel extends ViewModel {
|
||||||
constructor({createAndStartSessionContainer, sessionCallback, homeserver, deleteSessionOnCancel}) {
|
constructor(options) {
|
||||||
super();
|
super(options);
|
||||||
|
const {createAndStartSessionContainer, sessionCallback, homeserver, deleteSessionOnCancel} = options;
|
||||||
this._createAndStartSessionContainer = createAndStartSessionContainer;
|
this._createAndStartSessionContainer = createAndStartSessionContainer;
|
||||||
this._sessionCallback = sessionCallback;
|
this._sessionCallback = sessionCallback;
|
||||||
this._homeserver = homeserver;
|
this._homeserver = homeserver;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {ViewModel} from "./ViewModel.js";
|
||||||
|
|
||||||
class SessionItemViewModel extends ViewModel {
|
class SessionItemViewModel extends ViewModel {
|
||||||
constructor(sessionInfo, pickerVM) {
|
constructor(sessionInfo, pickerVM) {
|
||||||
super();
|
super({});
|
||||||
this._pickerVM = pickerVM;
|
this._pickerVM = pickerVM;
|
||||||
this._sessionInfo = sessionInfo;
|
this._sessionInfo = sessionInfo;
|
||||||
this._isDeleting = false;
|
this._isDeleting = false;
|
||||||
|
@ -100,8 +100,9 @@ class SessionItemViewModel extends ViewModel {
|
||||||
|
|
||||||
|
|
||||||
export class SessionPickerViewModel extends ViewModel {
|
export class SessionPickerViewModel extends ViewModel {
|
||||||
constructor({storageFactory, sessionInfoStorage, sessionCallback, createSessionContainer}) {
|
constructor(options) {
|
||||||
super();
|
super(options);
|
||||||
|
const {storageFactory, sessionInfoStorage, sessionCallback, createSessionContainer} = options;
|
||||||
this._storageFactory = storageFactory;
|
this._storageFactory = storageFactory;
|
||||||
this._sessionInfoStorage = sessionInfoStorage;
|
this._sessionInfoStorage = sessionInfoStorage;
|
||||||
this._sessionCallback = sessionCallback;
|
this._sessionCallback = sessionCallback;
|
||||||
|
|
|
@ -6,10 +6,10 @@ import {EventEmitter} from "../utils/EventEmitter.js";
|
||||||
import {Disposables} from "../utils/Disposables.js";
|
import {Disposables} from "../utils/Disposables.js";
|
||||||
|
|
||||||
export class ViewModel extends EventEmitter {
|
export class ViewModel extends EventEmitter {
|
||||||
constructor(options) {
|
constructor({clock} = {}) {
|
||||||
super();
|
super();
|
||||||
this.disposables = null;
|
this.disposables = null;
|
||||||
this._options = options;
|
this._options = {clock};
|
||||||
}
|
}
|
||||||
|
|
||||||
childOptions(explicitOptions) {
|
childOptions(explicitOptions) {
|
||||||
|
@ -21,6 +21,7 @@ export class ViewModel extends EventEmitter {
|
||||||
this.disposables = new Disposables();
|
this.disposables = new Disposables();
|
||||||
}
|
}
|
||||||
this.disposables.track(disposable);
|
this.disposables.track(disposable);
|
||||||
|
return disposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
@ -29,8 +30,18 @@ export class ViewModel extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disposeTracked(disposable) {
|
||||||
|
if (this.disposables) {
|
||||||
|
return this.disposables.disposeTracked(disposable);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this will need to support binding
|
// TODO: this will need to support binding
|
||||||
// if any of the expr is a function, assume the function is a binding, and return a binding function ourselves
|
// if any of the expr is a function, assume the function is a binding, and return a binding function ourselves
|
||||||
|
//
|
||||||
|
// translated string should probably always be bindings, unless we're fine with a refresh when changing the language?
|
||||||
|
// we probably are, if we're using routing with a url, we could just refresh.
|
||||||
i18n(parts, ...expr) {
|
i18n(parts, ...expr) {
|
||||||
// just concat for now
|
// just concat for now
|
||||||
let result = "";
|
let result = "";
|
||||||
|
@ -46,4 +57,8 @@ export class ViewModel extends EventEmitter {
|
||||||
emitChange(changedProps) {
|
emitChange(changedProps) {
|
||||||
this.emit("change", changedProps);
|
this.emit("change", changedProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get clock() {
|
||||||
|
return this._options.clock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue