I'm having issues with stores in Svelte. Currently, I'm using derived to update a filter as the stores get updated.
Here's an example of the function:
export const FILTERED_SORTED_BIDS = derived([PURCHASE_BIDS, FILTER_PARAMS, SORT_PARAMS], ([$PURCHASE_BIDS, $FILTER_PARAMS, $SORT_PARAMS]) => { let filteredData = $PURCHASE_BIDS; let filterCounter = 0; if ($FILTER_PARAMS.priority) { filteredData = filteredData.filter((item) => item.purchaseBid.priority == $FILTER_PARAMS.priority) filterCounter += 1 } // More filter conditions...}
This way, every time PURCHASE_BIDS, FILTER_PARAMS, or SORT_PARAMS changes, FILTERED_SORTED_BIDS should update. The problem here is that if I'm filtering using FILTER_PARAMS and I make a change in PURCHASE_BIDS, the change doesn't reach the derived function.
I make changes in PURCHASE_BIDS using an update like this:
PURCHASE_BIDS.update(bids => { bids[index].purchaseBid.priority = temPriority; return bids;});
From what I've read in the documentation, that should be enough. However, the updated value doesn't reach the derived function, causing reactivity issues. If I'm filtering, for example, by priority in my list, when I assign a new one, the previous one remains. However, if I'm not filtering (i.e., not using FILTER_PARAMS), there's no problem. I hope someone can guide me; it's my first time asking here. Thank you very much!
I hope that regardless of whether I'm filtering or not, the updated values reach the derived function, and thus avoid the reactivity problems I'm having.