Skip to content

Commit

Permalink
adjustment needed for refetch to work again
Browse files Browse the repository at this point in the history
  • Loading branch information
mskocik committed Feb 24, 2024
1 parent 2b7a5f6 commit 4dff8a7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/lib/Svelecte.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@
* @param {string|number|array} value
*/
export function refetchWith(value) {
fetch && fetch_runner({
if (!fetch) return;
fetch_runner({
init: true,
initValue: value
initValue: value,
storedValue: fetchResetOnBlur
});
fetchResetOnBlur = false; // force this to preven 'clearSelection' clear fetched options
}
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -804,7 +807,6 @@
prev_options = optionResolver(options, selectedKeys);
return;
}
options_flat = fetch && !fetch_initOnly && fetchResetOnBlur
? []
:options_flat;
Expand Down Expand Up @@ -1153,9 +1155,11 @@
}
}
/**
* @typedef {object} FetchOptions
* @property {boolean} [init=false]
* @property {any} [initValue]
* @typedef {{
* init?: boolean,
* initValue?: any,
* storedValue?: boolean
* }} FetchOptions
*
* @param {FetchOptions} opts
*/
Expand All @@ -1177,10 +1181,6 @@
// update fetchInitValue when fetch is changed, but we are in 'init' mode, ref #113
if (fetch_initOnly && prev_value && (!multiple || prev_value?.length > 0)) fetch_initValue = prev_value;
// reset found items
if (fetchResetOnBlur) prev_options = [];
// if (fetchResetOnBlur) prev_options = [];
const initial = fetch_initValue || opts.initValue;
if (fetch_initOnly) listMessage = i18n_actual.fetchInit;
Expand Down Expand Up @@ -1209,6 +1209,7 @@
if (initial) {
fetch_initValue = null; // always reset
watch_value_change(initial, { skipEqualityCheck: true });
if ('storedValue' in opts) fetchResetOnBlur = opts.storedValue; // related to re-fetch
}
})
})
Expand Down

0 comments on commit 4dff8a7

Please sign in to comment.