fix reactivity in lib/entity.ts
parent
b8fdf66cb3
commit
69ff2eb707
|
@ -1,12 +1,12 @@
|
||||||
import { IEntry, ListingResult } from "@/types/base";
|
import { IEntry, ListingResult } from "@/types/base";
|
||||||
import { fetcher } from "@/utils";
|
import { fetcher } from "@/utils";
|
||||||
import useSWRV from "swrv";
|
import useSWRV from "swrv";
|
||||||
import { computed } from "vue";
|
import { computed, Ref } from "vue";
|
||||||
|
|
||||||
|
|
||||||
export function useEntity(address: string) {
|
export function useEntity(address: string | (() => string)) {
|
||||||
const { data, error, mutate } = useSWRV<ListingResult, unknown>(
|
const { data, error, mutate } = useSWRV<ListingResult, unknown>(
|
||||||
() => `/api/obj/${address}`,
|
() => `/api/obj/${typeof address === "string" ? address : address()}`,
|
||||||
fetcher
|
fetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -23,11 +23,13 @@ export function useEntity(address: string) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const attributes = computed(() => {
|
const attributes = computed(() => {
|
||||||
return entries.value.filter(([_, e]) => e.entity === address);
|
const addr = typeof address === "string" ? address : address();
|
||||||
|
return entries.value.filter(([_, e]) => e.entity === addr);
|
||||||
});
|
});
|
||||||
|
|
||||||
const backlinks = computed(() => {
|
const backlinks = computed(() => {
|
||||||
return entries.value.filter(([_, e]) => e.entity !== address);
|
const addr = typeof address === "string" ? address : address();
|
||||||
|
return entries.value.filter(([_, e]) => e.entity !== addr);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -119,7 +119,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const { error, mutate, attributes, backlinks } = useEntity(props.address);
|
const { error, mutate, attributes, backlinks } = useEntity(() => props.address);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
attributes,
|
attributes,
|
||||||
|
|
Loading…
Reference in New Issue