Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function useFetch(
requestInfo: RequestInfo | Ref,
requestInit: RequestInit | Ref = {}
): AsyncFunctionReturn {
// always wrap arguments
const wrapReqInfo = isRef(requestInfo)
? requestInfo
: ref(requestInfo);
const wrapReqInit = isRef(requestInit)
? requestInit
: ref(requestInit);
async function doFetch(params: undefined, signal: AbortSignal) {
const requestInit = wrapReqInit.value;
const res = await fetch(wrapReqInfo.value, {
...requestInit,
signal
});
if (!res.ok) {
throw res;
}
// TODO figure out how to use typed headers
const headers: any = requestInit.headers;
if (headers && headers.Accept === "application/json") {
export function useAsync(
promiseFn: AsyncFunction | Ref>,
params?: P | Ref<p>
): AsyncFunctionReturn {
// always wrap arguments
const wrapPromiseFn = isRef>(promiseFn)
? promiseFn
: ref>(promiseFn);
const wrapParams: Ref</p><p> = isRef</p><p>(params) ? params : ref(params);
// create empty return values
const isLoading = ref(false);
const error = ref();
const data = ref();
// abort controller
let controller: AbortController | undefined;
function abort() {
isLoading.value = false;
if (controller !== undefined) {
controller.abort();</p>
export function wrap(o: RefTyped): Ref {
return isRef(o) ? o : ref(o);
}
function wrap(o) {
return compositionApi.isRef(o) ? o : compositionApi.ref(o);
}
const isFunction = (val) => typeof val === "function";
function normalizeOptions(opts: FieldAugmentedOptions | undefined): FieldOptions {
const defaults = {
value: ref(''),
immediate: false,
rules: ''
};
if (!opts) {
return defaults;
}
if (isRef(opts)) {
return {
...defaults,
rules: opts
};
}
if (typeof opts === 'string') {
return {
...defaults,
rules: opts
};
}
return {
...defaults,
...(opts ?? {})
watch(() => isRef(optionsRef) ? optionsRef.value : optionsRef, value => {
if (currentOptions.value && (
export function unwrap (val) {
return isRef(val) ? val.value : val
}
name: fieldName,
values: form?.valueRecords ?? {}
});
commitResult(result);
return result;
};
const handler = debounce(DELAY, validateField);
watch(value, handler, {
lazy: true
});
if (isRef(rules)) {
watch(rules as Ref, handler, {
lazy: true
});
} else if (hasRefs(rules)) {
Object.keys(rules).forEach(key => {
if (!isRef(rules[key])) {
return;
}
watch(rules[key], handler, { lazy: true });
});
}
const reset = () => {
const defaults = createFlags();
Object.keys(flags).forEach((key: string) => {
onMounted(() => {
const t = isRef(target) ? target.value : target;
t.addEventListener(type, handler, options);
});
export function unwrap(o: RefTyped): T {
return isRef(o) ? o.value : o;
}