({
config,
plugins,
eventBusConfig,
}: TanStackDevtoolsInit)
| 118 | } |
| 119 | |
| 120 | export default function SolidDevtoolsCore({ |
| 121 | config, |
| 122 | plugins, |
| 123 | eventBusConfig, |
| 124 | }: TanStackDevtoolsInit) { |
| 125 | // Convert plugins to the format expected by the core |
| 126 | const pluginsMap = createMemo<Array<TanStackDevtoolsPlugin> | undefined>(() => |
| 127 | plugins?.map((plugin) => ({ |
| 128 | ...plugin, |
| 129 | name: |
| 130 | typeof plugin.name === 'string' |
| 131 | ? plugin.name |
| 132 | : // The check above confirms that `plugin.name` is of Render type |
| 133 | (el, props) => |
| 134 | convertRender(el, plugin.name as SolidPluginRender, props), |
| 135 | render: (el: HTMLDivElement, props: TanStackDevtoolsPluginProps) => |
| 136 | convertRender(el, plugin.render, props), |
| 137 | })), |
| 138 | ) |
| 139 | |
| 140 | const convertTrigger = (el: HTMLElement, props: TriggerProps) => { |
| 141 | const Trigger = config?.customTrigger |
| 142 | |
| 143 | return ( |
| 144 | <Portal mount={el}> |
| 145 | {typeof Trigger === 'function' ? Trigger(el, props) : Trigger} |
| 146 | </Portal> |
| 147 | ) |
| 148 | } |
| 149 | const [devtools] = createSignal( |
| 150 | new TanStackDevtoolsCore({ |
| 151 | config: { |
| 152 | ...config, |
| 153 | customTrigger: config?.customTrigger |
| 154 | ? (el, props) => convertTrigger(el, props) |
| 155 | : undefined, |
| 156 | }, |
| 157 | eventBusConfig, |
| 158 | plugins: pluginsMap(), |
| 159 | }), |
| 160 | ) |
| 161 | let devToolRef: HTMLDivElement | undefined |
| 162 | |
| 163 | createEffect(() => { |
| 164 | devtools().setConfig({ |
| 165 | config: { |
| 166 | ...config, |
| 167 | customTrigger: config?.customTrigger |
| 168 | ? (el, props) => convertTrigger(el, props) |
| 169 | : undefined, |
| 170 | }, |
| 171 | }) |
| 172 | }) |
| 173 | |
| 174 | // Update plugins when they change |
| 175 | createEffect(() => { |
| 176 | const currentPlugins = pluginsMap() |
| 177 | if (currentPlugins) { |
nothing calls this directly
no test coverage detected