hubl/src/components/hubl-reactivity.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-11-20 14:57:12 +00:00
import { store, Sib, StoreMixin } from 'https://cdn.skypack.dev/@startinblox/core@0.13';
2020-06-18 18:02:54 +00:00
export const HublReactivity = {
name: 'hubl-reactivity',
use: [StoreMixin],
attributes: {
targetSrc: {
type: String,
default: '',
callback: function () {
this.subscribe();
}
},
dataSrc: {
type: String,
default: '',
callback: async function (value) {
this.resourceId = null;
if (this.nestedField) {
const resource = store.get(value) || await store.getData(value, this.context);
const nestedResource = await resource[this.nestedField]
this.resourceId = nestedResource ? nestedResource['@id'] : null;
} else {
this.resourceId = value;
}
this.subscribe();
}
},
},
subscribe() {
if (this.resourceId && this.targetSrc) {
store.subscribeVirtualContainerTo(this.resourceId, this.targetSrc);
store.subscribeVirtualContainerTo(this.targetSrc, this.resourceId);
2020-06-18 18:02:54 +00:00
}
}
}
Sib.register(HublReactivity);