On 2014-09-26, 3:18 AM, Alive wrote:
Hi folks,
During the cleanup work of gaia system app[1], I found that nearly every module
inside system app (and so many other apps),
is using a shared library called SettingsListener[2] to help it deal with
read/write/observe settings. This is nothing wrong, but actually I/we need more.
As I am a big fan to event listener interface and frequently use this pattern:
```js
var A = {
init: function() {
window.addEventListener('enabled', this);
window.addEventListener('locked', this);
}
handleEvent: function(evt) {
}
};
A.init();
```
|addEventListener| is possible to adopt an object or a function in its 2nd
argument,
but our mozSettings.addObserver can only adopt function..why? We have this
pattern in gecko code base![3]
If we could use the same or similar pattern for observing a settings change
it’d be great!
```js
var B = {
init: function() {
mozSettings.addObserver('lockscreen.enabled', this);
mozSettings.addObserver('lockscreen.locked', this);
},
observe: function(topic, value) {
}
};
B.init();
```
This anomaly is because of this callback type for
addObserver/removeObserver:
callback SettingChangeCallback = void (SettingChange setting);
I don't know why we decided to go with this type, but it seems to me
that we can just use something like:
callback interface SettingChangeCallback {
void handleEvent(SettingChange setting);
};
This is modeled after EventListener, with the difference that the
callback in EventListener takes an Event object.
This API is now exposed to third-party apps as well, but this change
should be backwards compatible (since you can still pass a function
where a callback interface is accepted.)
Also currently mozSettings.createLock().get()/set() doesn’t smell nice. A
promise is something developer wants.
It’d be nice if we have read/write without creating a lock and maintain on our
own.[4]
```js
mozSettings.read(‘lockscreen.enabled’).then(function(value) {});
mozSettings.write({‘lockscreen.enabled’: true}).then(function() {});
```
What about the rest of the functionality of SettingsLock, though?
<http://mxr.mozilla.org/mozilla-central/source/dom/webidl/SettingsManager.webidl#9>
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g