fix reactivity in lib/entity.ts

feat/vaults
Tomáš Mládek 2021-04-04 11:58:23 +02:00
parent b8fdf66cb3
commit 69ff2eb707
2 changed files with 8 additions and 6 deletions

View File

@ -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 {

View File

@ -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,