How to use the @vue/composition-api.onBeforeUnmount 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 vuejs / vue-apollo / packages / vue-apollo-composable / src / useSubscription.ts View on Github external
//   if (value == null) {
  //     enabled.value = enabledOption.value
  //   }
  // })

  // Auto start & stop
  watch(isEnabled, value => {
    if (value) {
      start()
    } else {
      stop()
    }
  })

  // Teardown
  onBeforeUnmount(stop)

  return {
    result,
    loading,
    error,
    // @TODO doesn't fully work yet
    // enabled,
    start,
    stop,
    restart,
    document: documentRef,
    variables: variablesRef,
    options: optionsRef,
    subscription,
    onResult: resultEvent.on,
    onError: errorEvent.on,
github davidkpiano / xstate / packages / xstate-vue / src / useMachine.ts View on Github external
);

  const initialState = rehydratedState
    ? State.create(rehydratedState)
    : service.initialState;

  const current = ref>(initialState);

  // extract send method for sending events to the service
  const send = (event: TEvent | TEvent['type']) => service.send(event);

  onBeforeMount(() => {
    service.start(rehydratedState ? initialState : undefined);
  });

  onBeforeUnmount(() => {
    service.stop();
  });

  return {
    current,
    service,
    send
  };
}
github vuejs / vue-apollo / packages / vue-apollo-composable / src / useQuery.ts View on Github external
//   if (value == null) {
  //     enabled.value = enabledOption.value
  //   }
  // })

  // Auto start & stop
  watch(isEnabled, value => {
    if (value) {
      start()
    } else {
      stop()
    }
  })

  // Teardown
  onBeforeUnmount(() => {
    stop()
    subscribeToMoreItems.length = 0
  })

  return {
    result,
    loading,
    networkStatus,
    error,
    // @TODO doesn't fully work yet
    // enabled,
    start,
    stop,
    restart,
    document: documentRef,
    variables: variablesRef,
github vuejs / vue-apollo / packages / vue-apollo-composable / src / util / loadingTracking.ts View on Github external
function track (loading: Ref, type: keyof LoadingTracking) {
  const { appTracking, tracking } = getCurrentTracking()

  watch(loading, (value, oldValue) => {
    if (oldValue != null && value !== oldValue) {
      const mod = value ? 1 : -1
      tracking[type].value += mod
      appTracking[type].value += mod
    }
  })

  onBeforeUnmount(() => {
    if (loading.value) {
      tracking[type].value--
      appTracking[type].value--
    }
  })
}
github logaretm / vue-use-web / src / EventListener.ts View on Github external
export function useEventListener(
  target: T | Ref,
  type: string,
  handler: EventListener,
  options?: AddEventListenerOptions
) {
  onMounted(() => {
    const t = isRef(target) ? target.value : target;

    t.addEventListener(type, handler, options);
  });

  onBeforeUnmount(() => {
    const t = isRef(target) ? target.value : target;

    t.removeEventListener(type, handler, options);
  });
}
github davidkpiano / xstate / packages / xstate-vue / src / fsm.ts View on Github external
export function useMachine(
  stateMachine: StateMachine.Machine
): {
  state: Ref>;
  send: StateMachine.Service['send'];
  service: StateMachine.Service;
} {
  const state = ref>(stateMachine.initialState);
  const service = interpret(stateMachine);
  const send = (event: TE | TE['type']) => service.send(event);

  service.subscribe(s => (state.value = s));
  service.start();

  onBeforeUnmount(() => {
    service.stop();
  });

  return { state, send, service };
}
github AlbertBrand / vue-async-function / lib / src / index.ts View on Github external
try {
      abort();
      isLoading.value = true;
      controller = new AbortController();
      const result = await newPromiseFn(newParams, controller.signal);
      error.value = undefined;
      data.value = result;
    } catch (e) {
      error.value = e;
      data.value = undefined;
    } finally {
      isLoading.value = false;
    }
  });

  onBeforeUnmount(abort);

  return {
    isLoading,
    error,
    data,
    abort,
    retry
  };
}