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();
```

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 do you think?


Best regard,
—
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1072757
[2] 
https://github.com/mozilla-b2g/gaia/blob/master/shared/js/settings_listener.js
[3] 
http://mxr.mozilla.org/mozilla-central/source/b2g/chrome/content/shell.js#944
[4] 
https://github.com/mozilla-b2g/gaia/blob/master/shared/js/settings_listener.js#L14-L29
-- 
Alive C. Kuo, Firefox OS, Senior Software Engineer at Mozilla Taiwan, Taipei 
office.
_______________________________________________
dev-b2g mailing list
dev-b2g@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to