Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

plugin.ts

48 lines1.0 KB

1import type { Type } from '@angular/core'
2import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
3​
4export interface DevtoolsPluginProps extends TanStackDevtoolsPluginProps {
5 [key: string]: any
6}
7​
8export type TanStackDevtoolsAngularPluginRenderFn<
9 TInputs extends DevtoolsPluginProps,
10> =
11 | ((inputs: () => TInputs, hostElement: HTMLElement) => () => void)
12 | Type<unknown>
13 | null
14​
15export type TanStackDevtoolsAngularPluginRender<
16 T extends DevtoolsPluginProps,
17> =
18 | Type<any>
19 | (() =>
20 | TanStackDevtoolsAngularPluginRenderFn<T>
21 | Promise<TanStackDevtoolsAngularPluginRenderFn<T>>)
22​
23export function createAngularPlugin<T extends DevtoolsPluginProps>({
24 render,
25 ...config
26}: {
27 name: string
28 id?: string
29 defaultOpen?: boolean
30 render: TanStackDevtoolsAngularPluginRender<T>
31}) {
32 function Plugin(inputs?: T | (() => T)) {
33 return {
34 ...config,
35 render,
36 inputs,
37 }
38 }
39​
40 function NoOpPlugin() {
41 return {
42 ...config,
43 render: null,
44 }
45 }
46​
47 return [Plugin, NoOpPlugin] as const