Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 11163046: Properly save modified objects in Prefs (Closed)

Created:
July 23, 2013, 10:32 p.m. by Felix Dahlke
Modified:
July 25, 2013, 10:06 a.m.
Reviewers:
Wladimir Palant
Visibility:
Public.

Description

Before this, changes to Prefs.notificationdata were never changed, since the object that was changed was actually defaults.notificationdata. Since objects aren't saved if they are identical to their default value, notificationdata was never changed at all. The best solution I could come up with was duplicate the default value and cache it, so that subsequent assignments don't overwrite prior ones.

Patch Set 1 #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+18 lines, -2 lines) Patch
M lib/prefs.js View 2 chunks +18 lines, -2 lines 4 comments Download

Messages

Total messages: 2
Felix Dahlke
July 23, 2013, 10:35 p.m. (2013-07-23 22:35:54 UTC) #1
Wladimir Palant
July 24, 2013, 8:49 a.m. (2013-07-24 08:49:40 UTC) #2
I've already addressed the issues in
https://hg.adblockplus.org/adblockpluschrome/rev/5c46367f8e7c and
https://hg.adblockplus.org/adblockpluschrome/rev/013c46ffd1a8.

http://codereview.adblockplus.org/11163046/diff/1/lib/prefs.js
File lib/prefs.js (right):

http://codereview.adblockplus.org/11163046/diff/1/lib/prefs.js#newcode42
lib/prefs.js:42: let cachedObjects = {};
Our property getter and setter are closures, we can use a local variable to
cache their value - no need for a global one for all prefs.

http://codereview.adblockplus.org/11163046/diff/1/lib/prefs.js#newcode63
lib/prefs.js:63: value = value || defaults[key];
What if value is false?

http://codereview.adblockplus.org/11163046/diff/1/lib/prefs.js#newcode65
lib/prefs.js:65: if (typeof value !== "object")
I don't really like the special case for objects here - if we cache preferences
then we should cache all of them.

http://codereview.adblockplus.org/11163046/diff/1/lib/prefs.js#newcode68
lib/prefs.js:68: cachedObjects[key] = JSON.parse(JSON.stringify(value));
This is wasteful - we only need the parse/stringify dance this if we take a
value from defaults, not if we already parsed it from localStorage.

Powered by Google App Engine
This is Rietveld