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