[main.js] now asynchronous page data loading -> each page script is a Promise() that must success before calling next() on VueRouter to load the according Vue

This commit is contained in:
xdrm-brackets 2018-04-07 16:11:59 +02:00
parent 51875ca4e8
commit 9150874287
4 changed files with 162 additions and 140 deletions

View File

@ -12,7 +12,7 @@ gs.get.router.beforeEach((to, from, next) => {
// {1} Ignore null name //
if( to.name == null )
next();
return next();
// {2} Get appropriate page location //
let auth_folder = (gs.get.authed) ? 'auth' : 'noauth';
@ -21,14 +21,16 @@ gs.get.router.beforeEach((to, from, next) => {
// {3} Load page script //
if( fullpath === 'noauth/login')
import('./page/noauth/login.js').then(next);
else if( fullpath === 'noauth/register')
import('./page/noauth/register.js').then(next);
else if( fullpath === 'auth/channel')
import('./page/auth/channel.js').then(next);
return require('./page/noauth/login.js').default.then(next);
if( fullpath === 'noauth/register')
return require('./page/noauth/register.js').default.then(next);
if( fullpath === 'auth/channel')
return require('./page/auth/channel.js').default.then(next);
// {4} Let VueRouter do the magic //
next();
// next();
});

View File

@ -3,6 +3,8 @@ import ContentController from '../../lib/content-controller'
import RoomController from '../../lib/room-controller'
import ChannelController from '../../lib/channel-controller'
export default new Promise( (res, rej) => {
/* (1) Channel data gathering
---------------------------------------------------------*/
/* (1) Store route params */
@ -25,3 +27,7 @@ gs.set('room', new RoomController());
/* (4) Initialize channels & channel menu */
gs.set('channel', new ChannelController());
gs.get.channel.fetch(); // fetch at load time
res();
});

View File

@ -1,3 +1,5 @@
export default new Promise( (res, rej) => {
/* (1) Initialise
---------------------------------------------------------*/
/* (1) Default data structure */
@ -74,3 +76,8 @@ gs.get.login.func.press_enter = function(e){
this.func.login();
}.bind(gs.get.login);
res();
});

View File

@ -1,3 +1,5 @@
export default new Promise( (res, rej) => {
/* (1) Initialise
---------------------------------------------------------*/
/* (1) Default data structure */
@ -81,3 +83,8 @@ gs.get.register.func.press_enter = function(e){
this.func.register();
}.bind(gs.get.register);
res();
});