How to use the @vue/composition-api.getCurrentInstance 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 / util / loadingTracking.ts View on Github external
export function getCurrentTracking () {
  const { appTracking } = getAppTracking()
  const currentInstance = getCurrentInstance()
  
  let tracking: LoadingTracking

  if (!appTracking.components.has(currentInstance)) {
    // Add per-component tracking
    appTracking.components.set(currentInstance, tracking = {
      queries: ref(0),
      mutations: ref(0),
      subscriptions: ref(0),
    })
    // Cleanup
    onUnmounted(() => {
      appTracking.components.delete(currentInstance)
    })
  } else {
    tracking = appTracking.components.get(currentInstance)
github vuejs / vue-apollo / packages / vue-apollo-composable / src / useSubscription.ts View on Github external
export function useSubscription <
  TResult = any,
  TVariables = OperationVariables
> (
  document: DocumentNode | Ref | ReactiveFunction,
  variables: TVariables | Ref | ReactiveFunction = null,
  options: UseSubscriptionOptions | Ref> | ReactiveFunction> = null
) {
  // Is on server?
  const vm = getCurrentInstance()
  const isServer = vm.$isServer

  if (variables == null) variables = ref()
  if (!options) options = {}
  const documentRef = paramToRef(document)
  const variablesRef = paramToRef(variables)
  const optionsRef = paramToReactive(options)

  const result = ref()
  const resultEvent = useEventHook>()
  const error = ref(null)
  const errorEvent = useEventHook()

  const loading = ref(false)
  trackSubscription(loading)
github vuejs / vue-apollo / packages / vue-apollo-composable / src / util / loadingTracking.ts View on Github external
export function getAppTracking () {
  const root: any = getCurrentInstance().$root
  let appTracking: AppLoadingTracking

  if (!root._apolloAppTracking) {
    // Add per Vue tracking
    appTracking = root._apolloAppTracking = {
      queries: ref(0),
      mutations: ref(0),
      subscriptions: ref(0),
      components: new Map(),
    }
  } else {
    appTracking = root._apolloAppTracking
  }

  return {
    appTracking
github vuejs / vue-apollo / packages / vue-apollo-composable / src / useQuery.ts View on Github external
export function useQuery<
  TResult = any,
  TVariables = OperationVariables,
  TCacheShape = any
> (
  document: DocumentNode | Ref | ReactiveFunction,
  variables: TVariables | Ref | ReactiveFunction = null,
  options: UseQueryOptions | Ref> | ReactiveFunction> = {},
) {
  // Is on server?
  const vm = getCurrentInstance()
  const isServer = vm.$isServer

  if (variables == null) variables = ref()
  if (options == null) options = {}
  const documentRef = paramToRef(document)
  const variablesRef = paramToRef(variables)
  const optionsRef = paramToReactive(options)

  // Result
  /**
   * Result from the query
   */
  const result = ref()
  const resultEvent = useEventHook>()
  const error = ref(null)
  const errorEvent = useEventHook()