Handle parent/child update events through broadcast bus events

This commit is contained in:
Fabio Manganiello 2023-01-21 16:58:28 +01:00
parent 3923a09831
commit 241670c9d0
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 19 additions and 2 deletions

View file

@ -28,7 +28,6 @@
:value="entity"
:loading="loading"
:level="level + 1"
@update="setJustUpdated"
@input="$emit('input', entity)" />
</div>
</div>
@ -38,11 +37,12 @@
<script>
import { defineAsyncComponent, shallowRef } from 'vue'
import EntityMixin from "./EntityMixin"
import { bus } from "@/bus";
export default {
name: "Entity",
mixins: [EntityMixin],
emits: ['input', 'loading'],
emits: ['input', 'loading', 'update'],
data() {
return {
@ -91,6 +91,15 @@ export default {
}
},
onEntityUpdate(entity) {
// Check if any of the children have been updated
const entityId = entity?.id
if (entityId == null || !(entityId in this.children))
return
this.setJustUpdated()
},
toggleCollapsed() {
this.collapsed = !this.collapsed
// Propagate the collapsed state to the wrapped component if applicable
@ -128,6 +137,8 @@ export default {
)
)
}
bus.onEntity(this.onEntityUpdate)
},
}
</script>

View file

@ -76,6 +76,7 @@ import NoItems from "@/components/elements/NoItems";
import Entity from "./Entity.vue";
import Selector from "./Selector.vue";
import EntityModal from "./Modal"
import { bus } from "@/bus";
import icons from '@/assets/icons.json'
import meta from './meta.json'
@ -320,6 +321,7 @@ export default {
}
this.entities[entityId] = entity
bus.publishEntity(entity)
},
onEntityDelete(event) {
@ -359,6 +361,10 @@ export default {
await this.sync()
await this.refresh()
},
unmounted() {
this.unsubscribe('on-entity-update')
},
}
</script>