Skip to content

Commit

Permalink
Improved: used nextTick instead of timeOut in segment change for obse…
Browse files Browse the repository at this point in the history
…rver (hotwax#606)
  • Loading branch information
amansinghbais committed Jan 15, 2025
1 parent 24ec014 commit d48a440
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/views/CountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ import {
} from '@ionic/vue';
import { chevronDownOutline, chevronUpOutline, closeOutline } from "ionicons/icons";
import { translate } from '@/i18n'
import { computed, defineProps, ref } from 'vue';
import { computed, defineProps, nextTick, ref } from 'vue';
import { useStore } from "@/store";
import { hasError } from '@/utils'
import logger from '@/logger'
Expand Down Expand Up @@ -428,7 +428,7 @@ async function scanProduct() {
queryString.value = ""
}
function updateFilteredItems() {
async function updateFilteredItems() {
if (itemsList.value.length > 0) {
// As we want to get the index of the product, if we directly store the product in the updatedProduct variable it does not return the index
// as both the object becomes different because of the reference, so if we have a product, then first finding it in the filtered list to have a common reference and then getting the index
Expand All @@ -441,7 +441,8 @@ function updateFilteredItems() {
} else {
store.dispatch("product/currentProduct", {});
}
setTimeout(() => { initializeObserver() }, 500);
await nextTick();
initializeObserver()
}
function initializeObserver() {
Expand Down
7 changes: 4 additions & 3 deletions src/views/HardCountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ import {
} from "@ionic/vue";
import { chevronDownOutline, chevronUpOutline, cloudOfflineOutline, paperPlaneOutline, trashOutline } from "ionicons/icons";
import { translate } from "@/i18n";
import { computed, defineProps, ref } from "vue";
import { computed, defineProps, nextTick, ref } from "vue";
import { useStore } from "@/store";
import logger from "@/logger";
import emitter from "@/event-bus";
Expand Down Expand Up @@ -315,7 +315,7 @@ async function fetchCycleCount() {
}
}
function handleSegmentChange() {
async function handleSegmentChange() {
if(itemsList.value.length) {
let updatedProduct = Object.keys(currentProduct.value)?.length ? itemsList.value.find((item: any) => isItemAlreadyAdded(item) ? (item.productId === currentProduct.value.productId && item.importItemSeqId === currentProduct.value.importItemSeqId) : (item.scannedId === currentProduct.value.scannedId)) : itemsList.value[0]
if(!updatedProduct) {
Expand All @@ -327,7 +327,8 @@ function handleSegmentChange() {
}
inputCount.value = ""
selectedCountUpdateType.value = defaultRecountUpdateBehaviour.value
setTimeout(() => { initializeObserver() }, 500);
await nextTick();
initializeObserver()
}
async function changeProduct(direction: string) {
Expand Down

0 comments on commit d48a440

Please sign in to comment.