|
|
@@ -1,22 +1,7 @@
|
|
|
import { FileDiff } from "@pierre/precision-diffs"
|
|
|
-import { getOrCreateWorkerPoolSingleton } from "@pierre/precision-diffs/worker"
|
|
|
-import { createEffect, onCleanup, splitProps } from "solid-js"
|
|
|
+import { createEffect, createMemo, onCleanup, splitProps } from "solid-js"
|
|
|
import { createDefaultOptions, type DiffProps, styleVariables } from "../pierre"
|
|
|
-import { workerFactory } from "../pierre/worker"
|
|
|
-
|
|
|
-const workerPool = getOrCreateWorkerPoolSingleton({
|
|
|
- poolOptions: {
|
|
|
- workerFactory,
|
|
|
- // poolSize defaults to 8. More workers = more parallelism but
|
|
|
- // also more memory. Too many can actually slow things down.
|
|
|
- // poolSize: 8,
|
|
|
- },
|
|
|
- highlighterOptions: {
|
|
|
- theme: "OpenCode",
|
|
|
- // Optionally preload languages to avoid lazy-loading delays
|
|
|
- // langs: ["typescript", "javascript", "css", "html"],
|
|
|
- },
|
|
|
-})
|
|
|
+import { workerPool } from "../pierre/worker"
|
|
|
|
|
|
// interface ThreadMetadata {
|
|
|
// threadId: string
|
|
|
@@ -28,21 +13,22 @@ export function Diff<T>(props: DiffProps<T>) {
|
|
|
let container!: HTMLDivElement
|
|
|
const [local, others] = splitProps(props, ["before", "after", "class", "classList", "annotations"])
|
|
|
|
|
|
- let fileDiffInstance: FileDiff<T> | undefined
|
|
|
- const cleanupFunctions: Array<() => void> = []
|
|
|
-
|
|
|
- createEffect(() => {
|
|
|
- container.innerHTML = ""
|
|
|
- if (!fileDiffInstance) {
|
|
|
- fileDiffInstance = new FileDiff<T>(
|
|
|
+ const fileDiff = createMemo(
|
|
|
+ () =>
|
|
|
+ new FileDiff<T>(
|
|
|
{
|
|
|
...createDefaultOptions(props.diffStyle),
|
|
|
...others,
|
|
|
},
|
|
|
workerPool,
|
|
|
- )
|
|
|
- }
|
|
|
- fileDiffInstance.render({
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ const cleanupFunctions: Array<() => void> = []
|
|
|
+
|
|
|
+ createEffect(() => {
|
|
|
+ container.innerHTML = ""
|
|
|
+ fileDiff().render({
|
|
|
oldFile: local.before,
|
|
|
newFile: local.after,
|
|
|
lineAnnotations: local.annotations,
|
|
|
@@ -52,7 +38,7 @@ export function Diff<T>(props: DiffProps<T>) {
|
|
|
|
|
|
onCleanup(() => {
|
|
|
// Clean up FileDiff event handlers and dispose SolidJS components
|
|
|
- fileDiffInstance?.cleanUp()
|
|
|
+ fileDiff()?.cleanUp()
|
|
|
cleanupFunctions.forEach((dispose) => dispose())
|
|
|
})
|
|
|
|