Skip to content

Commit

Permalink
Fire change so we save when a preference is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Aug 29, 2022
1 parent bcc5a30 commit 18c64ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/preferences.go
Expand Up @@ -73,9 +73,10 @@ func (p *InMemoryPreferences) get(key string) (interface{}, bool) {

func (p *InMemoryPreferences) remove(key string) {
p.lock.Lock()
defer p.lock.Unlock()

delete(p.values, key)
p.lock.Unlock()

p.fireChange()
}

func (p *InMemoryPreferences) fireChange() {
Expand Down
4 changes: 4 additions & 0 deletions internal/preferences_test.go
Expand Up @@ -141,7 +141,11 @@ func TestInMemoryPreferences_OnChange(t *testing.T) {

p.SetString("dummy", "another")
time.Sleep(time.Millisecond * 100)
assert.True(t, called)

called = false
p.RemoveValue("dummy")
time.Sleep(time.Millisecond * 100)
assert.True(t, called)
}

Expand Down

0 comments on commit 18c64ae

Please sign in to comment.