mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) add ability update cloudcmd without page reload
This commit is contained in:
parent
3db3e61e81
commit
a7ac83cbd3
1 changed files with 25 additions and 4 deletions
|
|
@ -5,6 +5,9 @@ require('../css/nojs.css');
|
|||
require('../css/columns/name-size-date.css');
|
||||
require('../css/columns/name-size.css');
|
||||
|
||||
const {promisify} = require('es6-promisify');
|
||||
const wraptile = require('wraptile/legacy');
|
||||
|
||||
const {
|
||||
registerSW,
|
||||
} = require('./sw/register');
|
||||
|
|
@ -22,14 +25,14 @@ module.exports = window.CloudCmd = (config) => {
|
|||
window.DOM = DOM;
|
||||
window.CloudCmd = require('./client');
|
||||
|
||||
registerSW(config.prefix);
|
||||
|
||||
const prefix = getPrefix(config.prefix);
|
||||
register(config);
|
||||
|
||||
require('./listeners');
|
||||
require('./key');
|
||||
require('./sort');
|
||||
|
||||
const prefix = getPrefix(config.prefix);
|
||||
|
||||
window.CloudCmd.init(prefix, config);
|
||||
};
|
||||
|
||||
|
|
@ -40,6 +43,24 @@ function getPrefix(prefix) {
|
|||
if (!prefix.indexOf('/'))
|
||||
return prefix;
|
||||
|
||||
return '/' + prefix;
|
||||
return `/${prefix}`;
|
||||
}
|
||||
|
||||
const onUpdateFound = wraptile(async (config) => {
|
||||
const {prefix} = config;
|
||||
|
||||
const js = promisify(window.DOM.load.js);
|
||||
const css = promisify(window.DOM.load.css);
|
||||
|
||||
await js(`${prefix}dist/cloudcmd.common.js`);
|
||||
await js(`${prefix}dist/cloudcmd.js`);
|
||||
|
||||
window.CloudCmd(config);
|
||||
});
|
||||
|
||||
async function register(config) {
|
||||
const {prefix} = config;
|
||||
const sw = await registerSW(prefix);
|
||||
|
||||
sw.addEventListener('updatefound', onUpdateFound(config));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue