mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
applyWithoutSync only when sync from main process
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
f73d87361a
commit
6477d5b4d2
@ -90,13 +90,19 @@ export class BaseStore<T = any> extends Singleton {
|
||||
if (ipcRenderer) {
|
||||
const callback = (event: IpcRendererEvent, model: T) => {
|
||||
logger.silly(`[STORE]: SYNC ${this.name} from main`, { model });
|
||||
this.onSync(model);
|
||||
this.onSyncFromMain(model);
|
||||
};
|
||||
ipcRenderer.on(this.syncChannel, callback);
|
||||
this.syncDisposers.push(() => ipcRenderer.off(this.syncChannel, callback));
|
||||
}
|
||||
}
|
||||
|
||||
protected onSyncFromMain(model: T) {
|
||||
this.applyWithoutSync(() => {
|
||||
this.onSync(model)
|
||||
})
|
||||
}
|
||||
|
||||
unregisterIpcListener() {
|
||||
ipcRenderer.removeAllListeners(this.syncChannel)
|
||||
}
|
||||
@ -116,11 +122,9 @@ export class BaseStore<T = any> extends Singleton {
|
||||
|
||||
protected onSync(model: T) {
|
||||
// todo: use "resourceVersion" if merge required (to avoid equality checks => better performance)
|
||||
this.applyWithoutSync(() => {
|
||||
if (!isEqual(this.toJSON(), model)) {
|
||||
this.fromStore(model);
|
||||
}
|
||||
})
|
||||
if (!isEqual(this.toJSON(), model)) {
|
||||
this.fromStore(model);
|
||||
}
|
||||
}
|
||||
|
||||
protected async onModelChange(model: T) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user