forked from firefox-devtools/debugger
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate log and defer utils (firefox-devtools#1064)
* annotate defer.js * add an interface file for devtools-config.js * annotate log.js * move flow type
- Loading branch information
1 parent
f0a51a8
commit 9a3c63b
Showing
4 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |