Skip to content

Commit

Permalink
moved boilerplate into util
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthropohedron committed Apr 7, 2015
1 parent 2900586 commit b30223e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var topics = [

function Controller() {
var me = this;
this.observerService = util.getService("@mozilla.org/observer-service;1",
this.observerService = util.getService("observer-service",
"nsIObserverService");
topics.forEach(function(topic) {
me.observerService.addObserver(me, topic, false);
Expand Down
11 changes: 9 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
var chrome = require("chrome");
var Cc = chrome.Cc;
var Ci = chrome.Ci;
var contractFrags = [
"@mozilla.org/",
null,
";1"
];

exports.createInstance = function createInstance(contractId, iface) {
return Cc[contractId].createInstance(Ci[iface]);
contractFrags[1] = contractId;
return Cc[contractFrags.join("")].createInstance(Ci[iface]);
};

exports.getService = function getService(contractId, service) {
return Cc[contractId].getService(Ci[service]);
contractFrags[1] = contractId;
return Cc[contractFrags.join("")].getService(Ci[service]);
};

0 comments on commit b30223e

Please sign in to comment.