views:

31

answers:

1

Let's say my Firefox extension has multiple preferences, but some of them are grouped, like check interval, fail retry interval, destination url. Those are used in just single function.

When I subscribe to preference service and add observer, the observe callback will be called for each changed preference, so if by chance user changed all of the settings in group, then I will have to do the same routine for the same subsystem as many times as I have items in that preferences group. It's a great redundancy!

What I want is observe to be called just once for group of preferences. Say

extensions.myextension.interval1
extensions.myextension.site
extensions.myextension.retry

so if one or all of those preferences are changed, I receive only 1 notification about it. In other words, no matter how many preferences changed in branch, I want the observe callback to called once.

A: 

When you register a pref observer on a branch (in your case, extensions.myextension), it will notify you about each preference change. There is no way to get it to tell you only once about a change on a branch. When your observe method is called, you do get the name of the preference that changes (it's the third parameter). You will have to filter your callbacks based on that.

sdwilsh
so how to `filter` in observer in order to run particular routine once for each group of preferences?
Michael
You'd have to track how many times you've been notified and only run your code once for ever X notifications, where X is the number of preferences on that pref branch.
sdwilsh
not a good solution. hope there will be better one, native to the framework architecture
Michael
Your use case wasn't really the intended one here for the API. The third argument of observe is the name of the preference changing, so you can just do the work you need to do for that preference.
sdwilsh