Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 992925 of preferences/event-target

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/preferences_event-target
  • Revision title: preferences/event-target
  • Revision id: 992925
  • Created:
  • Creator: wbamberg
  • Is current revision? Yes
  • Comment
Tags: 

Revision Content

{{AddonSidebar}}

Unstable

Listen to changes to the Preferences system in Firefox. This enables add-ons to listen to change events to the system-wide settings. These are the same preferences that are exposed to users in the about:config page.
 
preferences/service gives you full access to the preferences system. You can also use the simple-prefs module to access just the preferences for your own add-on and expose them to the user in the Add-on Manager.

Globals

Constructor

PrefsTarget(options)

Parameters

options : object
Required options:

Name Type  
branchName string

By default this is "", the root.

Example

var { PrefsTarget } = require("sdk/preferences/event-target");

// listen to the same branch which reqire("sdk/simple-prefs") does
var target = PrefsTarget({ branchName: "extensions." + require("sdk/self").preferencesBranch + "." });

target.once("test", function(prefName) {
  console.log(prefName) // logs "test"
  console.log(target.prefs[name]) // logs true
});

target.once("", function() {
  console.log(prefName) // logs "test"
  console.log(target.prefs[name]) // logs true
})

// changing a pref which our target listens to
require("sdk/simple-prefs").prefs.test = true;

Revision Source

{{AddonSidebar}}

<div class="note">
<p>Unstable</p>
</div>

<p><span class="seoSummary">Listen to changes to the <a href="/en-US/docs/Mozilla/Preferences">Preferences</a> system in Firefox.</span> This enables add-ons to listen to change events to the system-wide settings. These are the same preferences that are exposed to users in the <code>about:config</code> page.<br />
 &nbsp;<br />
 <code>preferences/service</code> gives you full access to the preferences system. You can also use the <a href="/en-US/Add-ons/SDK/High-Level_APIs/simple-prefs">simple-prefs</a> module to access just the preferences for your own add-on and expose them to the user in the <a href="/en-US/docs/Mozilla/Add-ons/Add-on_Manager">Add-on Manager</a>.</p>

<h2 id="Globals">Globals</h2>

<h3 id="Constructor">Constructor</h3>

<h4 class="addon-sdk-api-name" id="PrefsTarget(options)"><code>PrefsTarget(options)</code></h4>

<h5 id="Parameters">Parameters</h5>

<p><strong>options : object</strong><br />
 Required options:</p>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Name</th>
   <th scope="col">Type</th>
   <th scope="col">&nbsp;</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>branchName</td>
   <td>string</td>
   <td>
    <p>By default this is <code>""</code>, the root.</p>
   </td>
  </tr>
 </tbody>
</table>

<h2 id="Example">Example</h2>

<pre class="brush: js">
var { PrefsTarget } = require("sdk/preferences/event-target");

// listen to the same branch which reqire("sdk/simple-prefs") does
var target = PrefsTarget({ branchName: "extensions." + require("sdk/self").preferencesBranch + "." });

target.once("test", function(prefName) {
  console.log(prefName) // logs "test"
  console.log(target.prefs[name]) // logs true
});

target.once("", function() {
  console.log(prefName) // logs "test"
  console.log(target.prefs[name]) // logs true
})

// changing a pref which our target listens to
require("sdk/simple-prefs").prefs.test = true;
</pre>
Revert to this revision