Skip to content

Commit 90ad5b5

Browse files
support trigger update from outside instance
1 parent 804c6c6 commit 90ad5b5

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/core",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.7",
6+
"version": "0.0.8",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/core/src/diff-file.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export class DiffFile {
126126

127127
unifiedLineLength: number = 0;
128128

129+
expandSplitAll: boolean = false;
130+
131+
expandUnifiedAll: boolean = false;
132+
129133
#id: string = "";
130134

131135
#clonedInstance = new Map<DiffFile, () => void>();
@@ -959,10 +963,12 @@ export class DiffFile {
959963
Object.keys(this.#splitHunksLines || {}).forEach((key) => {
960964
this.onSplitHunkExpand("all", +key, false);
961965
});
966+
this.expandSplitAll = true;
962967
} else {
963968
Object.keys(this.#unifiedHunksLines || {}).forEach((key) => {
964969
this.onUnifiedHunkExpand("all", +key, false);
965970
});
971+
this.expandUnifiedAll = true;
966972
}
967973

968974
this.notifyAll();
@@ -1004,6 +1010,7 @@ export class DiffFile {
10041010
this.#splitHunksLines![item.splitInfo.endHiddenIndex] = item;
10051011
}
10061012
});
1013+
this.expandSplitAll = false;
10071014
} else {
10081015
Object.values(this.#unifiedLines || {}).forEach((item) => {
10091016
if (!item.isHidden && item._isHidden) {
@@ -1032,6 +1039,7 @@ export class DiffFile {
10321039
this.#unifiedHunksLines![item.unifiedInfo.endHiddenIndex] = item;
10331040
}
10341041
});
1042+
this.expandUnifiedAll = false;
10351043
}
10361044

10371045
this.notifyAll();
@@ -1061,6 +1069,11 @@ export class DiffFile {
10611069
}
10621070
f();
10631071
});
1072+
1073+
// support update from outside instance
1074+
this.#clonedInstance.forEach((_, instance) => {
1075+
instance.notifyAll(true);
1076+
});
10641077
};
10651078

10661079
getUpdateCount = () => this.#updateCount;

ui/react-example/src/Example.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ export function Example() {
8888
}, [v]);
8989

9090
useEffect(() => {
91-
setTimeout(() => {
92-
console.log(ref.current?.getDiffFileInstance());
93-
}, 100);
9491
if (expandAll) {
9592
ref.current
9693
?.getDiffFileInstance?.()
@@ -297,7 +294,7 @@ export function Example() {
297294
<div className="w-full flex items-center">
298295
<svg
299296
xmlns="http://www.w3.org/2000/svg"
300-
xmlnsXlink="http://www.w3.org/1999/xlink"
297+
// xmlnsXlink="http://www.w3.org/1999/xlink"
301298
aria-hidden="true"
302299
role="img"
303300
width="35.93"
@@ -316,7 +313,7 @@ export function Example() {
316313
<div className="w-full flex items-center">
317314
<svg
318315
xmlns="http://www.w3.org/2000/svg"
319-
xmlnsXlink="http://www.w3.org/1999/xlink"
316+
// xmlnsXlink="http://www.w3.org/1999/xlink"
320317
aria-hidden="true"
321318
role="img"
322319
width="37.07"

0 commit comments

Comments
 (0)