Skip to content

Commit

Permalink
fix: debounce setting file write
Browse files Browse the repository at this point in the history
fixes #149
  • Loading branch information
linonetwo committed Dec 1, 2021
1 parent 65fe7db commit 83c3ba3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/services/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { injectable } from 'inversify';
import { app } from 'electron';
import settings from 'electron-settings';
import { pickBy, mapValues } from 'lodash';
import { pickBy, mapValues, debounce } from 'lodash';
import { v4 as uuid } from 'uuid';
import path from 'path';
import fsExtra from 'fs-extra';
Expand All @@ -25,6 +25,8 @@ import type { IWorkspaceService, IWorkspace, IWorkspaceMetaData, INewWorkspaceCo
import i18n from '@services/libs/i18n';
import { defaultServerIP } from '@/constants/urls';

const debouncedSetSettingFile = debounce(async (id: string, workspace: IWorkspace) => await settings.set(`workspaces.${id}`, { ...workspace }), 500);

@injectable()
export class Workspace implements IWorkspaceService {
/**
Expand Down Expand Up @@ -194,7 +196,7 @@ export class Workspace implements IWorkspaceService {
public async set(id: string, workspace: IWorkspace): Promise<void> {
this.workspaces[id] = this.sanitizeWorkspace(workspace);
await this.reactBeforeWorkspaceChanged(workspace);
await settings.set(`workspaces.${id}`, { ...workspace });
await debouncedSetSettingFile(id, workspace);
await this.updateWorkspaceSubject();
await this.updateWorkspaceMenuItems();
}
Expand Down

0 comments on commit 83c3ba3

Please sign in to comment.