import { AsyncLocalStorage } from 'async_hooks'

export const fnStorage = new AsyncLocalStorage<{ fns: string[] }>()

// Designate a function in a .tsx file as frontend
export function frontend(code: Function) {
  const store = fnStorage.getStore()
  store?.fns.push(code.toString())
}

export function feFunctions(): string[] {
  const store = fnStorage.getStore()
  return store?.fns ?? []
}
