Skip to content

Commit

Permalink
[Config] Acknowledge when Advanced Settings response
Browse files Browse the repository at this point in the history
This adds a return value to the `Promise` returned by `config.set`, which
allows callers to `await` it  and verify that their setting was applied
without checking the settings (which is a race condition).
  • Loading branch information
pickypg committed Feb 2, 2018
1 parent fb2ff4f commit 1c0b7b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/ui/public/config/__tests__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ describe('config component', function () {
expect(config.set).withArgs('unrecognizedProperty', 'somevalue').to.not.throwException();
expect(config.get('unrecognizedProperty')).to.be('somevalue');
});

// there is currently no way to make it return false without significant changes to the code
it('returns true for success', async () => {
expect(await config.set('random', 'value')).to.be(true);
// setting to the same should set it to true as well
expect(await config.set('random', 'value')).to.be(true);
});
});

describe('#$bind', function () {
Expand Down
4 changes: 3 additions & 1 deletion src/ui/public/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ any custom setting configuration watchers for "${key}" may fix this issue.`);
const newVal = key in defaults && defaults[key].defaultValue === value ? null : value;
const unchanged = oldVal === newVal;
if (unchanged) {
return Promise.resolve();
return Promise.resolve(true);
}
const initialVal = declared ? config.get(key) : undefined;
localUpdate(key, newVal, initialVal);

return delayedUpdate(key, newVal)
.then(updatedSettings => {
settings = mergeSettings(defaults, updatedSettings);
return true;
})
.catch(reason => {
localUpdate(key, initialVal, config.get(key));
notify.error(reason);
return false;
});
}

Expand Down

0 comments on commit 1c0b7b7

Please sign in to comment.