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

plugin.ts

46 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<T extends DevtoolsPluginProps> =
16 | Type<any>
17 | (() =>
18 | TanStackDevtoolsAngularPluginRenderFn<T>
19 | Promise<TanStackDevtoolsAngularPluginRenderFn<T>>)
20​
21export function createAngularPlugin<T extends DevtoolsPluginProps>({
22 render,
23 ...config
24}: {
25 name: string
26 id?: string
27 defaultOpen?: boolean
28 render: TanStackDevtoolsAngularPluginRender<T>
29}) {
30 function Plugin(inputs?: T | (() => T)) {
31 return {
32 ...config,
33 render,
34 inputs,
35 }
36 }
37​
38 function NoOpPlugin() {
39 return {
40 ...config,
41 render: null,
42 }
43 }
44​
45 return [Plugin, NoOpPlugin] as const