Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit value change source in storage change event #185605

Closed
wants to merge 10 commits into from

Conversation

joyceerhl
Copy link
Collaborator

For #183449

Currently we emit a change event when a component like breakpoints writes to a key that it owns updates for. Since we now want components which may previously not have handled onDidChangeValue to register listeners for it, which can be emitted as part of a Continue On transition, it makes adoption easier on components if they avoid handling onDidChangeValue when the source is the component itself.

@joyceerhl joyceerhl enabled auto-merge (squash) June 19, 2023 18:58
@joyceerhl joyceerhl self-assigned this Jun 19, 2023
@joyceerhl joyceerhl requested a review from bpasero June 19, 2023 18:58
@vscodenpa vscodenpa added this to the June 2023 milestone Jun 19, 2023
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒 , besides my feedback this change also seems to miss any kind of unit test?

src/vs/base/parts/storage/common/storage.ts Outdated Show resolved Hide resolved
src/vs/base/parts/storage/common/storage.ts Outdated Show resolved Hide resolved
src/vs/base/parts/storage/common/storage.ts Outdated Show resolved Hide resolved
@joyceerhl joyceerhl requested a review from bpasero June 21, 2023 17:19
@joyceerhl joyceerhl requested a review from bpasero June 21, 2023 21:37
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I look at all the users of wasChangedExternally: true, it always seems to be from a loop over many keys and values. We could also simply have a new method storeAll that accepts an array of keys and values and that one will internally set the parameter. Might allow us to do other interesting things, such as only emitting the storage change events when all keys have been set. If a listener of storage change event depends on other state, we could then ensure the state is consistent at that point when the event is fired.

@@ -118,8 +118,10 @@ export interface IStorageService {
*
* @param target allows to define the target of the storage operation
* to either the current machine or user.
*
* @param source allows to specify the source of the storage change.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems outdated with the new boolean

}

private accept(key: string, value: string | undefined): void {
private accept(key: string, value: string | undefined, wasChangedExternally = false): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set false as default as the method is only called with a boolean?

@@ -52,9 +52,14 @@ export interface IStorageDatabase {
close(recovery?: () => Map<string, string>): Promise<void>;
}

export interface IStorageChangeEvent {
readonly key: string;
readonly wasChangedExternally?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to put the same JSDoc comment here explaining what it means.

@@ -278,7 +283,7 @@ export class Storage extends Disposable implements IStorage {
this.pendingInserts.delete(key);

// Event
this._onDidChangeStorage.fire(key);
this._onDidChangeStorage.fire({ key, wasChangedExternally: false });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to allow to pass in wasChangedExternally also for delete? What if a settings sync removes a key because its value changed to a default value?

@@ -607,13 +617,13 @@ export abstract class AbstractStorageService extends Disposable implements IStor

const newValue = newStorage.get(key);
if (newValue !== oldValue) {
this.emitDidChangeValue(scope, key);
this.emitDidChangeValue(scope, { key, wasChangedExternally: true });
Copy link
Member

@bpasero bpasero Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about newStorage.set(key, value); in line 608, shouldnt that also wasChangedExternally: true?

@bpasero
Copy link
Member

bpasero commented Jun 22, 2023

I am exploring the storeAll idea in #185837, which I will give you to review shortly. It is based on this work.

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed my feedback in #185837

@joyceerhl joyceerhl closed this Jun 22, 2023
auto-merge was automatically disabled June 22, 2023 14:44

Pull request was closed

@github-actions github-actions bot locked and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants