Skip to content

Commit

Permalink
#204: Implementation of the unsubscribe functionality onUnmounted
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailmarcu committed Feb 22, 2022
1 parent 025b07a commit ce30f78
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/vue/src/composables/useAssets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, ComputedRef, onBeforeMount, Ref, ref, watch } from 'vue'
import { computed, ComputedRef, onBeforeMount, onUnmounted, Ref, ref, watch } from 'vue'
import { Store } from 'vuex'

import { Amount, DenomTrace } from '@/utils/interfaces'
Expand All @@ -23,6 +23,7 @@ type Params = {
}

export default function ({ $s, opts }: Params): Response {

// state
let balances = ref({
isLoading: true,
Expand All @@ -36,6 +37,8 @@ export default function ({ $s, opts }: Params): Response {
// actions
let queryAllBalances = (opts: any) =>
$s.dispatch('cosmos.bank.v1beta1/QueryAllBalances', opts)
let unsubscribeBalances = (subscription: any) =>
$s.dispatch('cosmos.bank.v1beta1/unsubscribe', subscription)

// lh
onBeforeMount(async () => {
Expand All @@ -47,6 +50,16 @@ export default function ({ $s, opts }: Params): Response {
}
})

onUnmounted(async () => {
unsubscribeBalances( {
action: 'QueryBalance',
payload: {
params: { address: address.value },
options: { subscribe: true }
}
})
})

// computed
let balancesRaw = computed<any[]>(() => {
return (
Expand Down

0 comments on commit ce30f78

Please sign in to comment.