Skip to content

Commit

Permalink
fix(DamageCalculatorPage): use watchIgnorable instead extra watch target
Browse files Browse the repository at this point in the history
  • Loading branch information
rudnovd committed Apr 14, 2023
1 parent 003f9bb commit 0419d6f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/views/DamageCalculatorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
import CalculatorTabs from '@/components/CalculatorTabs.vue'
import DamageCalculator from '@/components/DamageCalculator.vue'
import { Battle } from '@/models/Battle'
import { watchIgnorable } from '@vueuse/shared'
import type { Ref } from 'vue'
import { computed, defineAsyncComponent, defineComponent, ref, watch } from 'vue'
import { computed, defineAsyncComponent, defineComponent, ref } from 'vue'
import { useI18n } from 'vue-i18n'
export default defineComponent({
Expand All @@ -63,7 +64,6 @@ export default defineComponent({
const calculators = ref<Array<Battle>>([new Battle()]) as Ref<Array<Battle>>
const activeIndex = ref(0)
const isStarted = ref(false)
const attacker = computed(() => calculators.value[activeIndex.value].attacker)
const defender = computed(() => calculators.value[activeIndex.value].defender)
Expand Down Expand Up @@ -174,21 +174,15 @@ export default defineComponent({
]
})
watch(
const { ignoreUpdates } = watchIgnorable(
[attacker, defender],
() => {
if (!attacker.value.activeCreature?.id || !defender.value.activeCreature?.id) return
else if (isStarted.value) return
calculators.value[activeIndex.value].calculate()
isStarted.value = true
ignoreUpdates(() => calculators.value[activeIndex.value].calculate())
},
{ deep: true }
)
watch(isStarted, (newIsStarted) => {
if (newIsStarted) isStarted.value = false
})
const addCalculator = () => {
calculators.value.push(new Battle())
activeIndex.value = calculators.value.length - 1
Expand Down

0 comments on commit 0419d6f

Please sign in to comment.