From 57f29262e3fe7fa2d1b622febc329b455d3bd4a1 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sat, 21 Dec 2019 13:40:34 -0500 Subject: [PATCH] [O] Separate checkIndex --- src/logic/nav-controller.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/logic/nav-controller.ts b/src/logic/nav-controller.ts index 6aa4177..270432f 100644 --- a/src/logic/nav-controller.ts +++ b/src/logic/nav-controller.ts @@ -48,16 +48,13 @@ export default class NavController */ updateIndex(index: Index | string, history?: boolean) { - // Convert index format if it is hash only - if (typeof index == 'string') index = {hash: index, identifier: index}; + index = this.checkIndex(index); // Call custom event if (this.updateCallback != null) this.updateCallback(); // Null case if (history == null) history = true; - if (index.title == null) index.title = FormatUtils.toTitleCase(index.hash); - // Record history or not if (history) { @@ -78,6 +75,20 @@ export default class NavController this.index = index; } + /** + * Check index conversion + * + * @param index Hash and title | Hash only + * @return Index Hash and title + */ + private checkIndex(index: Index | string): Index + { + // Convert index format if it is hash only + if (typeof index == 'string') index = {hash: index, identifier: index}; + if (index.title == null) index.title = FormatUtils.toTitleCase(index.hash); + return index; + } + get id(): string { return this.index.identifier