forked from platypush/platypush
Handle parent/child update events through broadcast bus events
This commit is contained in:
parent
3923a09831
commit
241670c9d0
2 changed files with 19 additions and 2 deletions
|
@ -28,7 +28,6 @@
|
||||||
:value="entity"
|
:value="entity"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:level="level + 1"
|
:level="level + 1"
|
||||||
@update="setJustUpdated"
|
|
||||||
@input="$emit('input', entity)" />
|
@input="$emit('input', entity)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,11 +37,12 @@
|
||||||
<script>
|
<script>
|
||||||
import { defineAsyncComponent, shallowRef } from 'vue'
|
import { defineAsyncComponent, shallowRef } from 'vue'
|
||||||
import EntityMixin from "./EntityMixin"
|
import EntityMixin from "./EntityMixin"
|
||||||
|
import { bus } from "@/bus";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Entity",
|
name: "Entity",
|
||||||
mixins: [EntityMixin],
|
mixins: [EntityMixin],
|
||||||
emits: ['input', 'loading'],
|
emits: ['input', 'loading', 'update'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
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() {
|
toggleCollapsed() {
|
||||||
this.collapsed = !this.collapsed
|
this.collapsed = !this.collapsed
|
||||||
// Propagate the collapsed state to the wrapped component if applicable
|
// Propagate the collapsed state to the wrapped component if applicable
|
||||||
|
@ -128,6 +137,8 @@ export default {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bus.onEntity(this.onEntityUpdate)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -76,6 +76,7 @@ import NoItems from "@/components/elements/NoItems";
|
||||||
import Entity from "./Entity.vue";
|
import Entity from "./Entity.vue";
|
||||||
import Selector from "./Selector.vue";
|
import Selector from "./Selector.vue";
|
||||||
import EntityModal from "./Modal"
|
import EntityModal from "./Modal"
|
||||||
|
import { bus } from "@/bus";
|
||||||
import icons from '@/assets/icons.json'
|
import icons from '@/assets/icons.json'
|
||||||
import meta from './meta.json'
|
import meta from './meta.json'
|
||||||
|
|
||||||
|
@ -320,6 +321,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entities[entityId] = entity
|
this.entities[entityId] = entity
|
||||||
|
bus.publishEntity(entity)
|
||||||
},
|
},
|
||||||
|
|
||||||
onEntityDelete(event) {
|
onEntityDelete(event) {
|
||||||
|
@ -359,6 +361,10 @@ export default {
|
||||||
await this.sync()
|
await this.sync()
|
||||||
await this.refresh()
|
await this.refresh()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
unmounted() {
|
||||||
|
this.unsubscribe('on-entity-update')
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue