2021-02-22 20:27:58 +00:00
|
|
|
import {
|
|
|
|
store,
|
|
|
|
Sib,
|
|
|
|
StoreMixin
|
2021-03-16 14:27:30 +00:00
|
|
|
} from 'https://cdn.skypack.dev/@startinblox/core@0.16';
|
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();
|
|
|
|
}
|
|
|
|
},
|
2020-12-02 09:35:21 +00:00
|
|
|
},
|
|
|
|
async fetchData(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();
|
2020-06-18 18:02:54 +00:00
|
|
|
},
|
|
|
|
subscribe() {
|
|
|
|
if (this.resourceId && this.targetSrc) {
|
|
|
|
store.subscribeVirtualContainerTo(this.resourceId, this.targetSrc);
|
2020-06-23 18:29:12 +00:00
|
|
|
store.subscribeVirtualContainerTo(this.targetSrc, this.resourceId);
|
2020-06-18 18:02:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Sib.register(HublReactivity);
|