How to use the @vue/composition-api.isRef function in @vue/composition-api

To help you get started, we’ve selected a few @vue/composition-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AlbertBrand / vue-async-function / lib / src / index.ts View on Github external
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") {
github AlbertBrand / vue-async-function / lib / src / index.ts View on Github external
export function useAsync(
  promiseFn: AsyncFunction | Ref>,
  params?: P | Ref<p>
): AsyncFunctionReturn {
  // always wrap arguments
  const wrapPromiseFn = isRef&gt;(promiseFn)
    ? promiseFn
    : ref&gt;(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>
github pikax / vue-composable / packages / core / src / utils.ts View on Github external
export function wrap(o: RefTyped): Ref {
  return isRef(o) ? o : ref(o);
}
github pikax / vue-composable / dist / vue-composable.cjs.js View on Github external
function wrap(o) {
    return compositionApi.isRef(o) ? o : compositionApi.ref(o);
}
const isFunction = (val) => typeof val === "function";
github logaretm / vue-use-form / src / useField.ts View on Github external
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 ?? {})
github vuejs / vue-apollo / packages / vue-apollo-composable / src / useQuery.ts View on Github external
  watch(() => isRef(optionsRef) ? optionsRef.value : optionsRef, value => {
    if (currentOptions.value && (
github vuelidate / vuelidate / packages / validators / src / utils / common.js View on Github external
export function unwrap (val) {
  return isRef(val) ? val.value : val
}
github logaretm / vue-use-form / src / useField.ts View on Github external
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 =&gt; {
      if (!isRef(rules[key])) {
        return;
      }

      watch(rules[key], handler, { lazy: true });
    });
  }

  const reset = () =&gt; {
    const defaults = createFlags();
    Object.keys(flags).forEach((key: string) =&gt; {
github logaretm / vue-use-web / src / EventListener.ts View on Github external
onMounted(() => {
    const t = isRef(target) ? target.value : target;

    t.addEventListener(type, handler, options);
  });
github pikax / vue-composable / packages / core / src / utils.ts View on Github external
export function unwrap(o: RefTyped): T {
  return isRef(o) ? o.value : o;
}