1
0
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:
Lauri Nevala 2020-10-22 20:10:15 +03:00
parent f73d87361a
commit 6477d5b4d2

View File

@ -90,13 +90,19 @@ export class BaseStore<T = any> extends Singleton {
if (ipcRenderer) { if (ipcRenderer) {
const callback = (event: IpcRendererEvent, model: T) => { const callback = (event: IpcRendererEvent, model: T) => {
logger.silly(`[STORE]: SYNC ${this.name} from main`, { model }); logger.silly(`[STORE]: SYNC ${this.name} from main`, { model });
this.onSync(model); this.onSyncFromMain(model);
}; };
ipcRenderer.on(this.syncChannel, callback); ipcRenderer.on(this.syncChannel, callback);
this.syncDisposers.push(() => ipcRenderer.off(this.syncChannel, callback)); this.syncDisposers.push(() => ipcRenderer.off(this.syncChannel, callback));
} }
} }
protected onSyncFromMain(model: T) {
this.applyWithoutSync(() => {
this.onSync(model)
})
}
unregisterIpcListener() { unregisterIpcListener() {
ipcRenderer.removeAllListeners(this.syncChannel) ipcRenderer.removeAllListeners(this.syncChannel)
} }
@ -116,11 +122,9 @@ export class BaseStore<T = any> extends Singleton {
protected onSync(model: T) { protected onSync(model: T) {
// todo: use "resourceVersion" if merge required (to avoid equality checks => better performance) // todo: use "resourceVersion" if merge required (to avoid equality checks => better performance)
this.applyWithoutSync(() => { if (!isEqual(this.toJSON(), model)) {
if (!isEqual(this.toJSON(), model)) { this.fromStore(model);
this.fromStore(model); }
}
})
} }
protected async onModelChange(model: T) { protected async onModelChange(model: T) {