once again forgotten observer optimization
parent
ce60bf5198
commit
c4db0b5479
|
@ -63,7 +63,7 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
|
|
||||||
// Identification
|
// Identification
|
||||||
const { attributes } = useEntity(props.address);
|
const { attributes } = useEntity(props.address, () => visible.value);
|
||||||
const inferredEntries = identify(attributes);
|
const inferredEntries = identify(attributes);
|
||||||
const inferredIds: ComputedRef<string[]> = computed(() => {
|
const inferredIds: ComputedRef<string[]> = computed(() => {
|
||||||
return inferredEntries.value.map((eid) => eid.value);
|
return inferredEntries.value.map((eid) => eid.value);
|
||||||
|
|
|
@ -4,9 +4,9 @@ import useSWRV from "swrv";
|
||||||
import { computed, ComputedRef, Ref } from "vue";
|
import { computed, ComputedRef, Ref } from "vue";
|
||||||
|
|
||||||
|
|
||||||
export function useEntity(address: string | (() => string)) {
|
export function useEntity(address: string | (() => string), condition?: () => Boolean) {
|
||||||
const { data, error, mutate } = useSWRV<ListingResult, unknown>(
|
const { data, error, mutate } = useSWRV<ListingResult, unknown>(
|
||||||
() => `/api/obj/${typeof address === "string" ? address : address()}`,
|
() => (condition === undefined || condition()) ? `/api/obj/${typeof address === "string" ? address : address()}` : null,
|
||||||
fetcher
|
fetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ export function identify(attributes: ComputedRef<[string, IEntry][]>): ComputedR
|
||||||
.map(([_, entry]) => entry.value.c);
|
.map(([_, entry]) => entry.value.c);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// Out of those, retrieve their TYPE_ID entries
|
// Out of those, retrieve their TYPE_ID entries
|
||||||
const { data: typeIdListing } = useSWRV<ListingResult, unknown>(() => {
|
const { data: typeIdListing } = useSWRV<ListingResult, unknown>(() => {
|
||||||
return isEntries.value && `/api/obj?query=(matches (in ${isEntries.value.map((e) => `"${e}"`).join(" ")}) "TYPE_ID" ?)`;
|
return isEntries.value && `/api/obj?query=(matches (in ${isEntries.value.map((e) => `"${e}"`).join(" ")}) "TYPE_ID" ?)`;
|
||||||
|
@ -66,6 +67,8 @@ export function identify(attributes: ComputedRef<[string, IEntry][]>): ComputedR
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Finally, filter own object's attributes according to TYPE_IDs
|
// Finally, filter own object's attributes according to TYPE_IDs
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
// For each identity/TYPE_ID pair
|
// For each identity/TYPE_ID pair
|
||||||
|
|
Loading…
Reference in New Issue