Skip to content

Commit

Permalink
Annotate log and defer utils (firefox-devtools#1064)
Browse files Browse the repository at this point in the history
* annotate defer.js
* add an interface file for devtools-config.js
* annotate log.js
* move flow type
  • Loading branch information
AbhiGulati authored and jasonLaster committed Nov 2, 2016
1 parent f0a51a8 commit 9a3c63b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .flowconfig
Expand Up @@ -5,3 +5,6 @@
.*node_modules/config-chain.*
.*firefox/.*
.*flow-coverage-report/.*

[libs]
./packages/devtools-config/flow-interface.js
12 changes: 12 additions & 0 deletions packages/devtools-config/flow-interface.js
@@ -0,0 +1,12 @@
declare module "devtools-config" {
declare module.exports: {
isDevelopment: () => boolean;
getValue: (key: string) => any;
isEnabled: () => boolean;
isTesting: () => boolean;
isFirefoxPanel: () => boolean;
isFirefox: () => boolean;
setConfig: (value: Object) => void;
getConfig: () => Object;
}
}
26 changes: 20 additions & 6 deletions public/js/utils/defer.js
@@ -1,12 +1,26 @@
module.exports = function defer() {
let resolve, reject;
let promise = new Promise(function() {
resolve = arguments[0];
reject = arguments[1];
/* flow */

export type deferred = {
resolve: (result: any) => void,
reject: (result: any) => void,
promise: Promise
};

function defer(): deferred {
let resolve: (result: any) => void;
let reject: (result: any) => void;
let promise = new Promise(function(
innerResolve: (result: any) => void,
innerReject: (result: any) => void
) {
resolve = innerResolve;
reject = innerReject;
});
return {
resolve: resolve,
reject: reject,
promise: promise
};
};
}

module.exports = defer;
6 changes: 4 additions & 2 deletions public/js/utils/log.js
@@ -1,11 +1,13 @@
/* @flow */

const { isDevelopment } = require("devtools-config");

function log() {
function log(...args: any[]) {
if (!isDevelopment()) {
return;
}

console.log.apply(console, ["[log]", ...arguments]);
console.log.apply(console, ["[log]", ...args]);
}

module.exports = log;

0 comments on commit 9a3c63b

Please sign in to comment.