forked from rc/aircox
hot reload
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
|
||||
export const defaultConfig = {
|
||||
el: '#app',
|
||||
delimiters: ['[[', ']]'],
|
||||
@ -12,12 +11,12 @@ export const defaultConfig = {
|
||||
},
|
||||
|
||||
computed: {
|
||||
player() { return window.aircox.player; }
|
||||
player() { return window.aircox.player; },
|
||||
},
|
||||
}
|
||||
|
||||
export default function App(config) {
|
||||
return (new AppConfig(config)).load()
|
||||
export default function App(config, sync=false) {
|
||||
return (new AppConfig(config)).load(sync)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,30 +29,36 @@ export class AppConfig {
|
||||
|
||||
get config() {
|
||||
let config = this._config instanceof Function ? this._config() : this._config;
|
||||
return {...defaultConfig, ...config};
|
||||
for(var k of new Set([...Object.keys(config || {}), ...Object.keys(defaultConfig)])) {
|
||||
if(!config[k] && defaultConfig[k])
|
||||
config[k] = defaultConfig[k]
|
||||
else if(config[k] instanceof Object)
|
||||
config[k] = {...defaultConfig[k], ...config[k]}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
set config(value) {
|
||||
this._config = value;
|
||||
}
|
||||
|
||||
load() {
|
||||
load(sync=false) {
|
||||
var self = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
window.addEventListener('load', () => {
|
||||
try {
|
||||
let config = self.config;
|
||||
const el = document.querySelector(config.el)
|
||||
if(!el) {
|
||||
reject(`Error: missing element ${config.el}`);
|
||||
return;
|
||||
}
|
||||
resolve(new Vue(config))
|
||||
}
|
||||
catch(error) { reject(error) }
|
||||
})
|
||||
let func = () => { try { resolve(self.build()) } catch(error) { reject(error) }};
|
||||
sync ? func() : window.addEventListener('load', func);
|
||||
});
|
||||
}
|
||||
|
||||
build() {
|
||||
let config = this.config;
|
||||
const el = document.querySelector(config.el)
|
||||
if(!el) {
|
||||
reject(`Error: missing element ${config.el}`);
|
||||
return;
|
||||
}
|
||||
return new Vue(config);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user