refactoring, config stuff basically OK
This commit is contained in:
parent
5f793c354e
commit
2dca568ee8
4 changed files with 39 additions and 61 deletions
|
@ -1,11 +1,18 @@
|
||||||
|
import { createApp } from './lib/petite-vue.es.js'
|
||||||
|
|
||||||
import { api, polling } from './settings'
|
import { api, polling } from './settings'
|
||||||
|
import { pageid } from '@params'
|
||||||
|
|
||||||
type confdata = {
|
type confdata = {
|
||||||
|
apiurl: string
|
||||||
pollurl: string
|
pollurl: string
|
||||||
|
itemid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function config (api, polling): confdata {
|
export function config (api, polling): confdata {
|
||||||
return { pollurl: '' }
|
const pu = `${api.path}/${polling.msgbase.join('/')}`
|
||||||
|
const urlparams = new URL(location.href).searchParams
|
||||||
|
return { apiurl: api.path, pollurl: pu, itemid: urlparams.get('id') }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pvapp = {
|
export const pvapp = {
|
||||||
|
@ -13,17 +20,36 @@ export const pvapp = {
|
||||||
conf: {} as confdata,
|
conf: {} as confdata,
|
||||||
data: {},
|
data: {},
|
||||||
output: '',
|
output: '',
|
||||||
|
run,
|
||||||
save,
|
save,
|
||||||
poll
|
poll,
|
||||||
|
newdata: '',
|
||||||
|
mounted(name: string) {
|
||||||
|
console.log('app mounted: ', name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// method definitions
|
// pvapp method definitions
|
||||||
|
|
||||||
|
function run(conf: confdata) {
|
||||||
|
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
|
||||||
//this.newdata = ''
|
console.log('save:', value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function poll() {
|
||||||
|
dopoll(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// basic functions
|
||||||
|
|
||||||
async function dopoll(app: typeof pvapp) {
|
async function dopoll(app: typeof pvapp) {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
@ -39,7 +65,3 @@ async function dopoll(app: typeof pvapp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function poll() {
|
|
||||||
dopoll(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,52 +1,5 @@
|
||||||
import { createApp } from './lib/petite-vue.es.js'
|
|
||||||
import { pageid } from '@params'
|
|
||||||
console.log("pageid:", pageid)
|
|
||||||
|
|
||||||
import { api, polling } from './settings'
|
import { api, polling } from './settings'
|
||||||
import { config, pvapp } from './common'
|
import { config, pvapp } from './common'
|
||||||
// pvapp.run(config(api, polling))
|
|
||||||
|
|
||||||
const pollUrl = `${api.path}/${polling.msgbase.join('/')}`
|
pvapp.run(config(api, polling))
|
||||||
console.log("pollUrl:", pollUrl)
|
|
||||||
|
|
||||||
const appdata = {
|
|
||||||
$delimiters: ['{|', '|}'],
|
|
||||||
urlParams: new URL(location.href).searchParams,
|
|
||||||
poll,
|
|
||||||
newdata: '',
|
|
||||||
data: '',
|
|
||||||
save,
|
|
||||||
mounted(name: string) {
|
|
||||||
console.log('app mounted: ', name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createApp(appdata).mount()
|
|
||||||
|
|
||||||
appdata.poll()
|
|
||||||
|
|
||||||
// method definitions
|
|
||||||
|
|
||||||
function save() {
|
|
||||||
this.data += '\n' + this.newdata
|
|
||||||
this.newdata = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
async function dopoll(obj: typeof appdata, url: string) {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
let res = await fetch(url)
|
|
||||||
let data = await res.json()
|
|
||||||
console.log(data)
|
|
||||||
obj.newdata = data['status']
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
await new Promise(r => setTimeout(r, 10000))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function poll() {
|
|
||||||
dopoll(this, pollUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -9,3 +9,5 @@ export const pageid = 'pageid-dummy'
|
||||||
export const domain = 'domain-dummy'
|
export const domain = 'domain-dummy'
|
||||||
export const action = 'action-dummy'
|
export const action = 'action-dummy'
|
||||||
export const class_ = 'class-dummy'
|
export const class_ = 'class-dummy'
|
||||||
|
|
||||||
|
export const nopolling = false
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
<div v-scope>
|
<div v-scope>
|
||||||
<input type="text" name="txt" autofocus
|
<input type="text" name="txt" autofocus
|
||||||
v-model="newdata"
|
v-model="data.txt"
|
||||||
@change="save" />
|
@vue:mounted="$el.value = ''"
|
||||||
|
@change="save($el.value)" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-scope @vue:mounted="mounted('data')">
|
<div v-scope @vue:mounted="mounted('data')">
|
||||||
<pre v-text="data"></pre>
|
<pre v-text="data"></pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-scope>
|
<div v-scope @vue:mounted="mounted('output')">
|
||||||
<pre v-text="newdata" @vue:mounted="mounted('newdata')"></pre>
|
<pre v-text="output"></pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-scope>
|
<div v-scope>
|
||||||
<div>id = {| urlParams.get('id') |}</div>
|
<div>id = {| conf.itemid |}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue