mount app after start of polling to set up session on server before first query
This commit is contained in:
parent
b75aa08d7c
commit
71c683a9f7
1 changed files with 15 additions and 5 deletions
|
@ -29,10 +29,10 @@ export function config (api, polling): Config {
|
||||||
export const pvapp = {
|
export const pvapp = {
|
||||||
run(conf: Config) {
|
run(conf: Config) {
|
||||||
appdata.conf = conf
|
appdata.conf = conf
|
||||||
createApp(appdata).mount()
|
|
||||||
if (appdata.conf.pollurl && !appdata.conf.nopoll) {
|
if (appdata.conf.pollurl && !appdata.conf.nopoll) {
|
||||||
appdata.poll()
|
appdata.poll()
|
||||||
}
|
}
|
||||||
|
createApp(appdata).mount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +49,13 @@ const appdata = {
|
||||||
Data
|
Data
|
||||||
}
|
}
|
||||||
|
|
||||||
// components
|
// Data component
|
||||||
// (move to separate module(s))
|
// (move to comp_data.ts)
|
||||||
|
|
||||||
function Data(name, action, domain: string): object {
|
function Data(name, action, domain: string): object {
|
||||||
domain = domain || this.conf.domain
|
domain = domain || this.conf.domain
|
||||||
const comp = {
|
const comp = {
|
||||||
|
id: this.conf.itemid,
|
||||||
name: name, // -> class of incoming/outgoing message
|
name: name, // -> class of incoming/outgoing message
|
||||||
action: action, // (default) action of outgoing message
|
action: action, // (default) action of outgoing message
|
||||||
domain: domain, // domain of incoming/outgoing message
|
domain: domain, // domain of incoming/outgoing message
|
||||||
|
@ -68,10 +69,14 @@ function Data(name, action, domain: string): object {
|
||||||
exec // default function to execute upon button click
|
exec // default function to execute upon button click
|
||||||
}
|
}
|
||||||
this.components[name] = comp
|
this.components[name] = comp
|
||||||
|
if (comp.id) {
|
||||||
|
sendMsg(this.conf, [domain, 'query', name, comp.id], {})
|
||||||
|
}
|
||||||
return comp
|
return comp
|
||||||
}
|
}
|
||||||
|
|
||||||
// appdata and component method definitions
|
// Data methods
|
||||||
|
// (move to comp_data.ts)
|
||||||
|
|
||||||
function mounted(name: string, meta: any) {
|
function mounted(name: string, meta: any) {
|
||||||
if (meta.defexpr) {
|
if (meta.defexpr) {
|
||||||
|
@ -120,6 +125,8 @@ function exec(action: string) {
|
||||||
sendMsg(conf, [this.domain, action, this.name, data.id], data)
|
sendMsg(conf, [this.domain, action, this.name, data.id], data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// App (appdata) methods
|
||||||
|
|
||||||
function handle(msg) {
|
function handle(msg) {
|
||||||
const data = JSON.parse(msg.payload)
|
const data = JSON.parse(msg.payload)
|
||||||
const [ domain, action, class_, item ] = msg.path.split('/')
|
const [ domain, action, class_, item ] = msg.path.split('/')
|
||||||
|
@ -129,6 +136,8 @@ function handle(msg) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (comp) {
|
if (comp) {
|
||||||
|
// TODO: use more generic comp.update(data)
|
||||||
|
// ... or even more generic comp.handle(msg)
|
||||||
Object.assign(comp.data, data)
|
Object.assign(comp.data, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +146,8 @@ function poll() {
|
||||||
dopoll(this)
|
dopoll(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions for data manipulation
|
// helper functions for data manipulation (used by Data component)
|
||||||
|
// (move to comp_data.ts)
|
||||||
|
|
||||||
function setQuery(obj) {
|
function setQuery(obj) {
|
||||||
for (const key in obj.data) {
|
for (const key in obj.data) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue