use register() method in app object to correctly register component scope

This commit is contained in:
Helmut Merz 2023-03-24 08:17:48 +01:00
parent a377688175
commit bf2c1bfa91
3 changed files with 11 additions and 6 deletions

View file

@ -48,6 +48,7 @@ const appdata = {
conf: {} as Config, conf: {} as Config,
components: {}, components: {},
output: '', // debug output space output: '', // debug output space
register,
handle, handle,
poll, poll,
Data Data
@ -55,6 +56,10 @@ const appdata = {
// App (appdata) methods // App (appdata) methods
function register(name: string, comp: any) {
this.components[name] = comp
}
function handle(msg) { function handle(msg) {
const [ domain, action, class_, item ] = msg.path.split('/') const [ domain, action, class_, item ] = msg.path.split('/')
const comp = this.components[class_ || 'data'] const comp = this.components[class_ || 'data']

View file

@ -1,6 +1,5 @@
// comp-data.ts - definition and methods of the Data component // comp-data.ts - definition and methods of the Data component
import { reactive } from 'petite-vue'
import { sendMsg } from './common' import { sendMsg } from './common'
// Data component // Data component
@ -24,7 +23,7 @@ export function Data(name: string, conf: any): object {
chmode, chmode,
copynew copynew
} }
this.components[name] = reactive(comp) //this.components[name] = comp
if (comp.state.id) { if (comp.state.id) {
sendMsg(this.conf, [domain, 'query', name, comp.state.id], {}) sendMsg(this.conf, [domain, 'query', name, comp.state.id], {})
} }
@ -34,11 +33,11 @@ export function Data(name: string, conf: any): object {
// Data methods // Data methods
function handle(parent: any, domain, action, class_, item, payload: string) { function handle(parent: any, domain, action, class_, item, payload: string) {
if (action == 'data') { // && this.state.id const data = JSON.parse(payload)
const data = JSON.parse(payload) if (action == 'data') { // && this.state.id == item) {
Object.assign(this.data, data) Object.assign(this.data, data)
this.state.mode = 'view' this.state.mode = 'view'
} else if (action == 'response') { } else if (action == 'response') { // && data.rc == 3) {
this.state.id = item this.state.id = item
window.location.hash = item window.location.hash = item
sendMsg(parent.conf, [this.domain, 'query', this.name, item], {}) sendMsg(parent.conf, [this.domain, 'query', this.name, item], {})

View file

@ -4,6 +4,7 @@
{{- $comp := .Get "component" | default "Data" -}} {{- $comp := .Get "component" | default "Data" -}}
{{- $conf := merge $.Params (dict "domain" $domain "action" $action) {{- $conf := merge $.Params (dict "domain" $domain "action" $action)
| jsonify -}} | jsonify -}}
<div v-scope="{{ $comp }}('{{ $name }}', {{ $conf }})"> <div v-scope="{{ $comp }}('{{ $name }}', {{ $conf }})"
@vue:mounted="register('{{ $name }}', valueOf())">
{{ .Inner }} {{ .Inner }}
</div> </div>