diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-07-11 15:03:32 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-07-11 15:09:56 +1000 |
| commit | 776692bc0a5115202774b715bd14d2cd505549dc (patch) | |
| tree | bb81866cddae09b57e648d83b74269d89cabead5 /src/App.vue | |
| parent | e77845075eaa813b5c8bf765023e0423f4327780 (diff) | |
Use initial-tree-cache to reduce initial load timeinitial-tree-cache
Diffstat (limited to 'src/App.vue')
| -rw-r--r-- | src/App.vue | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/App.vue b/src/App.vue index ecf2948..3bbb5cd 100644 --- a/src/App.vue +++ b/src/App.vue @@ -106,6 +106,7 @@ import {arraySum, randWeightedChoice, timeout} from './util'; // Constants const SERVER_WAIT_MSG = 'Loading data'; const PROCESSING_WAIT_MSG = 'Processing'; +import initialTrees from './initialTrees.json'; // Cached server data used to reduce load time // Type representing auto-mode actions type AutoAction = 'move across' | 'move down' | 'move up' | Action; // Function used in auto-mode to reduce action cycles @@ -941,14 +942,19 @@ export default defineComponent({ // Get possible target node from URL let nodeName = (new URL(window.location.href)).searchParams.get('node'); // Query server - let urlParams = new URLSearchParams({type: 'node', tree: this.uiOpts.tree}); - if (nodeName != null){ - urlParams.append('name', nodeName); - urlParams.append('toroot', '1'); - } - let responseObj: {[x: string]: TolNode} = await this.loadFromServer(urlParams); - if (responseObj == null){ - return; + let responseObj: {[x: string]: TolNode}; + if (nodeName == null && initialTrees != null){ // Use pre-stored initial-tree data + responseObj = initialTrees[this.uiOpts.tree as keyof typeof initialTrees]; + } else { + let urlParams = new URLSearchParams({type: 'node', tree: this.uiOpts.tree}); + if (nodeName != null){ + urlParams.append('name', nodeName); + urlParams.append('toroot', '1'); + } + responseObj = await this.loadFromServer(urlParams); + if (responseObj == null){ + return; + } } // Get root node name let rootName = null; @@ -1103,7 +1109,7 @@ export default defineComponent({ } }, }, - created(){ + mounted(){ window.addEventListener('resize', this.onResize); window.addEventListener('keydown', this.onKeyUp); this.initTreeFromServer(); |
