viewer: apply preference toggles immediately
The preferences object handed to Game as a prop was a plain object owned by launch(), and Vue 2 does not deep-observe prop values coming from a non-reactive parent. Toggling sound or the drag/drop help indicators mutated an unobserved object, so the UI only caught up on the next unrelated re-render (in practice: after a refresh). Make the object a Vue.observable and merge platform preference pushes into it instead of replacing it, so both the in-game toggles and platform updates paint immediately.
This commit is contained in:
parent
fd23b5c996
commit
1b6d749e31
1 changed files with 8 additions and 3 deletions
|
|
@ -13,10 +13,14 @@ function launch(selector: string) {
|
|||
} = {
|
||||
state: null,
|
||||
emitter: new EventEmitter(),
|
||||
preferences: {
|
||||
// Observable so preference changes update the UI immediately: Game receives
|
||||
// this object as a prop, and Vue 2 does not deep-observe prop values coming
|
||||
// from a non-reactive parent — plain-object mutations (the in-game sound/help
|
||||
// toggles, platform preference pushes) would only paint on the next re-render.
|
||||
preferences: Vue.observable({
|
||||
sound: true,
|
||||
disableHelp: false,
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const app = new Vue({
|
||||
|
|
@ -45,7 +49,8 @@ function launch(selector: string) {
|
|||
app.$forceUpdate();
|
||||
});
|
||||
item.addListener('preferences', (data) => {
|
||||
params.preferences = { ...params.preferences, ...data };
|
||||
// Mutate (don't replace) the observable object so the update stays reactive
|
||||
Object.assign(params.preferences, data);
|
||||
app.$forceUpdate();
|
||||
});
|
||||
item.addListener('gamelog', (logData) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue