From 5a308552275e3477def6c555b95f501cd2ca8beb Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 16 Oct 2020 13:02:21 +0200 Subject: [PATCH] rename urlRouter option in view models to urlCreator --- src/domain/LoginViewModel.js | 2 +- src/domain/RootViewModel.js | 4 ++-- src/domain/SessionPickerViewModel.js | 4 ++-- src/domain/ViewModel.js | 12 ++++++++---- src/domain/session/leftpanel/LeftPanelViewModel.js | 2 +- src/domain/session/leftpanel/RoomTileViewModel.js | 2 +- src/domain/session/room/RoomViewModel.js | 2 +- src/main.js | 4 +++- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/domain/LoginViewModel.js b/src/domain/LoginViewModel.js index 11ba3d73..a23ccb6f 100644 --- a/src/domain/LoginViewModel.js +++ b/src/domain/LoginViewModel.js @@ -70,7 +70,7 @@ export class LoginViewModel extends ViewModel { } get cancelUrl() { - return this.urlRouter.urlForSegment("session"); + return this.urlCreator.urlForSegment("session"); } dispose() { diff --git a/src/domain/RootViewModel.js b/src/domain/RootViewModel.js index b8ef2015..ae3fbc8e 100644 --- a/src/domain/RootViewModel.js +++ b/src/domain/RootViewModel.js @@ -38,7 +38,7 @@ export class RootViewModel extends ViewModel { async load() { this.track(this.navigation.observe("login").subscribe(() => this._applyNavigation())); this.track(this.navigation.observe("session").subscribe(() => this._applyNavigation())); - this._applyNavigation(this.urlRouter.getLastUrl()); + this._applyNavigation(this.urlCreator.getLastUrl()); } async _applyNavigation(restoreUrlIfAtDefault) { @@ -59,7 +59,7 @@ export class RootViewModel extends ViewModel { } else { try { if (restoreUrlIfAtDefault) { - this.urlRouter.pushUrl(restoreUrlIfAtDefault); + this.urlCreator.pushUrl(restoreUrlIfAtDefault); } else { const sessionInfos = await this._sessionInfoStorage.getAll(); if (sessionInfos.length === 0) { diff --git a/src/domain/SessionPickerViewModel.js b/src/domain/SessionPickerViewModel.js index ca9430b3..76be11dd 100644 --- a/src/domain/SessionPickerViewModel.js +++ b/src/domain/SessionPickerViewModel.js @@ -76,7 +76,7 @@ class SessionItemViewModel extends ViewModel { } get openUrl() { - return this.urlRouter.urlForSegment("session", this.id); + return this.urlCreator.urlForSegment("session", this.id); } get label() { @@ -189,6 +189,6 @@ export class SessionPickerViewModel extends ViewModel { } get cancelUrl() { - return this.urlRouter.urlForSegment("login"); + return this.urlCreator.urlForSegment("login"); } } diff --git a/src/domain/ViewModel.js b/src/domain/ViewModel.js index cccdb847..8c847247 100644 --- a/src/domain/ViewModel.js +++ b/src/domain/ViewModel.js @@ -30,8 +30,8 @@ export class ViewModel extends EventEmitter { } childOptions(explicitOptions) { - const {navigation, urlRouter, clock} = this._options; - return Object.assign({navigation, urlRouter, clock}, explicitOptions); + const {navigation, urlCreator, clock} = this._options; + return Object.assign({navigation, urlCreator, clock}, explicitOptions); } track(disposable) { @@ -99,8 +99,12 @@ export class ViewModel extends EventEmitter { return this._options.clock; } - get urlRouter() { - return this._options.urlRouter; + /** + * The url router, only meant to be used to create urls with from view models. + * @return {URLRouter} + */ + get urlCreator() { + return this._options.urlCreator; } get navigation() { diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index cca0ae06..9d57d6bd 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -44,7 +44,7 @@ export class LeftPanelViewModel extends ViewModel { this._roomList = this._roomListFilterMap.sortValues((a, b) => a.compare(b)); this._currentTileVM = null; this._setupNavigation(); - this._closeUrl = this.urlRouter.urlForSegment("session"); + this._closeUrl = this.urlCreator.urlForSegment("session"); } get closeUrl() { diff --git a/src/domain/session/leftpanel/RoomTileViewModel.js b/src/domain/session/leftpanel/RoomTileViewModel.js index 09cb6372..6cfea617 100644 --- a/src/domain/session/leftpanel/RoomTileViewModel.js +++ b/src/domain/session/leftpanel/RoomTileViewModel.js @@ -30,7 +30,7 @@ export class RoomTileViewModel extends ViewModel { this._isOpen = false; this._wasUnreadWhenOpening = false; this._hidden = false; - this._url = this.urlRouter.openRoomActionUrl(this._room.id); + this._url = this.urlCreator.openRoomActionUrl(this._room.id); if (options.isOpen) { this.open(); } diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 8c470370..d401c843 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -32,7 +32,7 @@ export class RoomViewModel extends ViewModel { this._sendError = null; this._composerVM = new ComposerViewModel(this); this._clearUnreadTimout = null; - this._closeUrl = this.urlRouter.urlUntilSegment("session"); + this._closeUrl = this.urlCreator.urlUntilSegment("session"); } get closeUrl() { diff --git a/src/main.js b/src/main.js index 792c333b..0b47c95d 100644 --- a/src/main.js +++ b/src/main.js @@ -143,7 +143,9 @@ export async function main(container, paths, legacyExtras) { sessionInfoStorage, storageFactory, clock, - urlRouter, + // the only public interface of the router is to create urls, + // so we call it that in the view models + urlCreator: urlRouter, navigation, updateService: serviceWorkerHandler });