Skip to content

Commit 6088de2

Browse files
authored
Merge pull request #22 from Kitware/fix-vue3-remount
fix(vue3): Fix vue3 components remounting every time a key is added to state
2 parents ca92820 + 9f1542a commit 6088de2

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Feature
88

9-
* **loading:** Enable loading screen to be overriden ([`9d13b21`](https://github.com/Kitware/trame-client/commit/9d13b21a7bc99feef6621c1c538f7bb505282616))
9+
* **loading:** Enable loading screen to be overridden ([`9d13b21`](https://github.com/Kitware/trame-client/commit/9d13b21a7bc99feef6621c1c538f7bb505282616))
1010

1111
## v2.15.0 (2024-01-17)
1212

vue3-app/src/components/TrameTemplate.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ export function setup() {
4040

4141
// Server update reactivity
4242
const onDirty = ({ type, keys }) => {
43+
if (type === "new-keys") {
44+
for (let i = 0; i < keys.length; i++) {
45+
const name = keys[i];
46+
if (publicAPI[name] === undefined) {
47+
publicAPI[name] = toRef(trame, name, modifiedState);
48+
}
49+
}
50+
}
51+
4352
if (type === "dirty-state") {
4453
for (let i = 0; i < keys.length; i++) {
4554
modifiedState[keys[i]]();

vue3-app/src/core/trame/state.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ export class SharedState {
5353
}
5454

5555
this.mtime += 1;
56-
let newKeyCount = 0;
56+
const newKeys = [];
5757
for (let i = 0; i < updatedKeys.length; i++) {
5858
const key = updatedKeys[i];
5959
if (this.keyTS[key] === undefined) {
60-
newKeyCount++;
60+
newKeys.push(key);
6161
}
6262
this.keyTS[key] = this.mtime;
6363
}
6464

65-
if (newKeyCount) {
66-
this.notifyListeners({ type: "refresh" });
67-
} else {
68-
this.notifyListeners({ type: "dirty-state", keys: updatedKeys });
65+
if (newKeys.length > 0) {
66+
this.notifyListeners({ type: "new-keys", keys: newKeys });
6967
}
68+
69+
this.notifyListeners({ type: "dirty-state", keys: updatedKeys });
7070
};
7171

7272
this.subscriptions.push(

0 commit comments

Comments
 (0)