From 696e7856f8ad2d597bca9b2139a3f2db928a5abd Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 9 Oct 2020 09:56:01 +0200 Subject: [PATCH] some cleanup --- src/domain/BrawlViewModel.js | 3 ++- src/domain/navigation/URLRouter.js | 3 ++- src/domain/navigation/index.js | 32 ++++++++++++++++++++++++++++++ src/main.js | 17 +++------------- 4 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 src/domain/navigation/index.js diff --git a/src/domain/BrawlViewModel.js b/src/domain/BrawlViewModel.js index 71aebb44..dde9bc44 100644 --- a/src/domain/BrawlViewModel.js +++ b/src/domain/BrawlViewModel.js @@ -39,6 +39,7 @@ export class BrawlViewModel extends ViewModel { } async load() { + // TODO: deduplicate code here this.track(this.navigation.observe("login").subscribe(shown => { if (shown) { this._showLogin(); @@ -125,7 +126,7 @@ export class BrawlViewModel extends ViewModel { sessionContainer.startWithExistingSession(sessionId); return sessionContainer; }, - sessionCallback: sessionContainer => this._sessionCallback(sessionContainer) + sessionCallback: this._sessionCallback }); this._sessionLoadViewModel.start(); }); diff --git a/src/domain/navigation/URLRouter.js b/src/domain/navigation/URLRouter.js index 2b7e8513..d0f66fe6 100644 --- a/src/domain/navigation/URLRouter.js +++ b/src/domain/navigation/URLRouter.js @@ -23,7 +23,7 @@ export class URLRouter { this._navigation = navigation; } - start() { + attach() { this._subscription = this._history.subscribe(url => { this._applyUrl(url); }); @@ -60,6 +60,7 @@ export class URLRouter { } replaceUrl(url) { + // TODO: we don't want this to always to trigger an update this._history.replaceUrl(url); } diff --git a/src/domain/navigation/index.js b/src/domain/navigation/index.js new file mode 100644 index 00000000..b4b9890e --- /dev/null +++ b/src/domain/navigation/index.js @@ -0,0 +1,32 @@ +/* +Copyright 2020 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import {Navigation} from "./Navigation.js"; + +export function createNavigation() { + return new Navigation(function allowsChild(parent, child) { + const {type} = child; + switch (parent?.type) { + case undefined: + // allowed root segments + return type === "login" || type === "session"; + case "session": + return type === "room" || type === "rooms" || type === "settings"; + default: + return false; + } + }); +} diff --git a/src/main.js b/src/main.js index 2ff9b4ad..13bab3ef 100644 --- a/src/main.js +++ b/src/main.js @@ -22,7 +22,7 @@ import {SessionContainer} from "./matrix/SessionContainer.js"; import {StorageFactory} from "./matrix/storage/idb/StorageFactory.js"; import {SessionInfoStorage} from "./matrix/sessioninfo/localstorage/SessionInfoStorage.js"; import {BrawlViewModel} from "./domain/BrawlViewModel.js"; -import {Navigation} from "./domain/navigation/Navigation.js"; +import {createNavigation} from "./domain/navigation/index.js"; import {URLRouter} from "./domain/navigation/URLRouter.js"; import {BrawlView} from "./ui/web/BrawlView.js"; import {Clock} from "./ui/web/dom/Clock.js"; @@ -118,20 +118,9 @@ export async function main(container, paths, legacyExtras) { workerPromise = loadOlmWorker(paths); } - const navigation = new Navigation(function allowsChild(parent, child) { - const {type} = child; - switch (parent?.type) { - case undefined: - // allowed root segments - return type === "login" || type === "session"; - case "session": - return type === "room" || type === "settings"; - default: - return false; - } - }); + const navigation = createNavigation(); const urlRouter = new URLRouter(new History(), navigation); - urlRouter.start(); + urlRouter.attach(); const vm = new BrawlViewModel({ createSessionContainer: () => {