upgrade vue and assets

This commit is contained in:
bkfox
2022-03-18 02:53:54 +01:00
parent 5b788ca28f
commit adb10c3d95
76 changed files with 2453 additions and 11975 deletions

50
assets/src/live.js Normal file
View File

@ -0,0 +1,50 @@
import {setEcoTimeout} from './utils';
import Model from './model';
export default class Live {
constructor({url,timeout=10,src=""}={}) {
this.url = url;
this.timeout = timeout;
this.src = src;
this.promise = null;
this.items = [];
}
get current() {
let item = this.items && this.items[this.items.length-1];
if(item)
item.src = this.src;
return item ? new Model(item) : null;
}
//-- data refreshing
drop() {
this.promise = null;
}
fetch() {
const promise = fetch(this.url).then(response =>
response.ok ? response.json()
: Promise.reject(response)
).then(data => {
this.items = data;
return this.items
})
this.promise = promise;
return promise;
}
refresh() {
const promise = this.fetch();
promise.then(() => {
if(promise != this.promise)
return [];
setEcoTimeout(() => this.refresh(), this.timeout*1000)
})
return promise
}
}