separate appdata from pvapp runner object

This commit is contained in:
Helmut Merz 2023-02-27 12:16:18 +01:00
parent 2dca568ee8
commit 126740ef14

View file

@ -15,29 +15,29 @@ export function config (api, polling): confdata {
return { apiurl: api.path, pollurl: pu, itemid: urlparams.get('id') } return { apiurl: api.path, pollurl: pu, itemid: urlparams.get('id') }
} }
export const pvapp = { const appdata = {
$delimiters: ['{|', '|}'], $delimiters: ['{|', '|}'],
conf: {} as confdata, conf: {} as confdata,
data: {}, data: {},
output: '', output: '',
run,
save, save,
poll, poll,
newdata: '',
mounted(name: string) { mounted(name: string) {
console.log('app mounted: ', name) console.log('app mounted: ', name)
} }
} }
// pvapp method definitions export const pvapp = {
run(conf: confdata) {
appdata.conf = conf
createApp(appdata).mount()
if (appdata.conf.pollurl) {
appdata.poll()
}
}
}
function run(conf: confdata) { // appdata method definitions
this.conf = conf
createApp(this).mount()
if (this.conf.pollurl) {
this.poll()
}
}
function save(value: string) { function save(value: string) {
this.output += '\n' + value this.output += '\n' + value
@ -50,10 +50,10 @@ function poll() {
// basic functions // basic functions
async function dopoll(app: typeof pvapp) { async function dopoll(app: typeof appdata) {
while (true) { while (true) {
try { try {
let res = await fetch(pvapp.conf.pollurl) let res = await fetch(app.conf.pollurl)
let msg = await res.json() let msg = await res.json()
console.log(msg) console.log(msg)
//app.handle(msg) //app.handle(msg)