components: +name, register in app; put sid in config object

This commit is contained in:
Helmut Merz 2023-03-03 09:25:37 +01:00
parent f345d7e8bc
commit 8a244aa1a3
3 changed files with 19 additions and 8 deletions

View file

@ -7,12 +7,18 @@ type confdata = {
apiurl: string apiurl: string
pollurl: string pollurl: string
itemid: string itemid: string
sid: string
} }
export function config (api, polling): confdata { export function config (api, polling): confdata {
const pu = polling ? `${api.path}/${polling.msgbase.join('/')}` : '' const pu = polling ? `${api.path}/${polling.msgbase.join('/')}` : ''
const urlparams = new URL(location.href).searchParams const urlparams = new URL(location.href).searchParams
return { apiurl: api.path, pollurl: pu, itemid: urlparams.get('id') } return {
apiurl: api.path,
pollurl: pu,
itemid: urlparams.get('id'),
sid: getSid()
}
} }
export const pvapp = { export const pvapp = {
@ -28,6 +34,7 @@ export const pvapp = {
const appdata = { const appdata = {
$delimiters: ['{|', '|}'], $delimiters: ['{|', '|}'],
conf: {} as confdata, conf: {} as confdata,
components: {},
output: '', output: '',
poll, poll,
mounted(name: string) { mounted(name: string) {
@ -39,11 +46,13 @@ const appdata = {
// components // components
function Data() { function Data(name: string): object {
return { const comp = {
data: {}, data: {},
save save
} }
appdata.components[name] = comp
return comp
} }
// appdata and component method definitions // appdata and component method definitions
@ -81,9 +90,9 @@ function getSid(): string {
return sid return sid
} }
console.log("sid: ", getSid()) //console.log("sid: ", getSid())
//localStorage.setItem('api.sessionid', '')
// TODO: clear sid - when? // TODO: clear sid - when?
//localStorage.setItem('api.sessionid', '')
async function dopoll(app: typeof appdata) { async function dopoll(app: typeof appdata) {
while (true) { while (true) {

View file

@ -1,7 +1,8 @@
<div v-scope> <div v-scope>
<div @vue:mounted="mounted('itemid')"> <div @vue:mounted="mounted('conf')">
<div>id = {| conf.itemid |}</div> <div>item id: {| conf.itemid |}</div>
<div>session id: {| conf.sid |}</div>
</div> </div>
<div @vue:mounted="mounted('output')"> <div @vue:mounted="mounted('output')">

View file

@ -1,3 +1,4 @@
<div v-scope="Data()"> {{- $name := .Get "name" | default "data" -}}
<div v-scope="Data('{{ $name }}')">
{{ .Inner }} {{ .Inner }}
</div> </div>