Browse Source

Merge pull request #2942 from nocodb/feat/use-injection-state

feat(gui-v2): add `useInjectionState` composable
pull/2943/head
Pranav C 2 years ago committed by GitHub
parent
commit
77f6170f89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/nc-gui-v2/composables/index.ts
  2. 19
      packages/nc-gui-v2/composables/useInjectionState/index.ts

1
packages/nc-gui-v2/composables/index.ts

@ -1,5 +1,6 @@
export * from './useApi'
export * from './useGlobal'
export * from './useInjectionState'
export * from './useUIPermission'
export * from './useAttachment'
export * from './useBelongsTo'

19
packages/nc-gui-v2/composables/useInjectionState/index.ts

@ -0,0 +1,19 @@
import type { InjectionKey } from 'vue'
export function useInjectionState<Arguments extends any[], Return>(
composable: (...args: Arguments) => Return,
): readonly [useProvidingState: (...args: Arguments) => void, useInjectedState: () => Return | undefined] {
const key: string | InjectionKey<Return> = Symbol('InjectionState')
const useProvidingState = (...args: Arguments) => {
const providedState = composable(...args)
provide(key, providedState)
return providedState
}
const useInjectedState = () => inject(key)
return [useProvidingState, useInjectedState]
}
Loading…
Cancel
Save