Bug 709382 require("simple-prefs").prefs should be iterable#300
Bug 709382 require("simple-prefs").prefs should be iterable#300Gozala merged 24 commits intomozilla:masterfrom erikvold:bug-709382
Conversation
There was a problem hiding this comment.
preferences-service is based on Preferences and is intended to be a cleaner, more friendly, and more JavaScript-y API than the underlying XPCOM interface. I'd like to maintain that friendliness as we add new functionality to it.
In particular, instead of introducing a "class method" that takes a branch name, we should make the exports object be a constructor that retains its existing class methods but also takes a branch name when called as a constructor (just like in Preferences) and from which consumers can retrieve the keys for the branch. And rather than calling the key retrieval method by a non-standard name like getChildList() that comes from the underlying XPCOM API, we should use the standard Object.keys() (like in simple-prefs).
So the API would then look like:
let Prefs = require("preferences-service");
let myPrefs = Prefs("foo.bar.baz");
console.log("My prefs are: " + Object.keys(myPrefs));
// It's still possible to call Prefs.get("foo.bar.baz.qux"), etc.
for.. in can be made to work on these instances, as can branch-scoped versions of the existing class methods like get() and set() (just like in Preferences), but those can happen in a separate change; they don't need to be part of this one.
… that Myk suggested
…nan code from simple-prefs) which is the 'simple-prefs' module now uses
Conflicts: packages/addon-kit/lib/simple-prefs.js packages/api-utils/lib/preferences-service.js packages/api-utils/tests/test-preferences-service.js
|
Mind taking a look at this one @Gozala ? |
…preference branch
|
I cleaned this up some and rebased it at #442 (I don't feel like I have authority to close requests here :) ) |
There was a problem hiding this comment.
Could you please change this to Branch(name) instead ?
There was a problem hiding this comment.
Could you please rename pref, val to key value.
|
Could we please tackle iterability separately from observability ? |
|
Do you plan to address this as well #300 (comment) ? |
|
Thanks for doing all of these BTW! |
…g-709382 Note: tests fail Conflicts: packages/addon-kit/lib/simple-prefs.js
|
merged with master now. |
|
I think this is ready for another review @Gozala |
There was a problem hiding this comment.
Please do not alias set / get / keys, ... on Branch constructor.
There was a problem hiding this comment.
Also we should stick to following export pattern:
function foo() {
// ...
}
exports.foo = foo;There was a problem hiding this comment.
Also please make sure to Proxy handler code to use method(branchName + pref) instead of Branch.method(branchName + pref) or exports.method(...
|
Just a small details left. Thanks ;) |
|
Looks good, thanks a lot! |
fix Bug 709382 require("simple-prefs").prefs should be iterable r=@Gozala
https://bugzilla.mozilla.org/show_bug.cgi?id=709382