Skip to content

Commit

Permalink
[TIMOB-13379] Address review comments
Browse files Browse the repository at this point in the history
'ES6-ify' code, add default and optional to documentation
  • Loading branch information
ewanharris committed Apr 6, 2018
1 parent 8bd6d1d commit 9df50b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion android/runtime/common/src/js/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Titanium": false
},
"parserOptions": {
"ecmaVersion": 5,
"ecmaVersion": 6,
"sourceType": "script"
}
}
30 changes: 13 additions & 17 deletions android/runtime/common/src/js/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
var times = {};
const times = new Map();
function join(args) {
// Handle null / undefined args up front since we can't slice them
if (typeof args === 'undefined') {
Expand Down Expand Up @@ -46,27 +46,23 @@ exports.debug = function () {
Titanium.API.debug(join(arguments));
};

exports.time = function (label) {
if (times[label]) {
exports.warn('Label "' + label + '" already exists');
exports.time = function (label = 'default') {
label = `${label}`;
if (times.has(label)) {
exports.warn(`Label ${label}" already exists`);
return;
}
if (!label) {
label = 'default';
}
times[label] = Date.now();
times.set(label, Date.now());
};

exports.timeEnd = function (label) {
if (!label) {
label = 'default';
}
var startTime = times[label];
exports.timeEnd = function (label = 'default') {
label = `${label}`;
const startTime = times.get(label);
if (!startTime) {
exports.warn('Label "' + label + '" does not exist');
exports.warn(`Label "${label}" does not exist`);
return;
}
var duration = Date.now() - startTime;
exports.log(label + ': ' + duration + 'ms');
delete times[label];
const duration = Date.now() - startTime;
exports.log(`${label}: ${duration}ms`);
times.delete(label);
};
24 changes: 15 additions & 9 deletions apidoc/Global/console/console.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,32 @@ methods:
- name: message
summary: The message(s) to log.
type: Object

- name: time
summary: Start a timer to track duration of an operation.
description: |
Begin a timer that can be used to track the duration of an operation.
If not label is passed to the function it will default to "default",
if a label already exists then the existing label will not be overwritten
If no label is passed to the function it will default to "default".
If a label already exists then the existing label will not be overwritten
and a warning will be logged to the console.
parameters:
- name: label
summary: The label to track the timer by, defaults to "default".
summary: The label to track the timer by
type: String
optional: true
default: "default"
since: 7.2.0

- name: timeEnd
summary: Stop a timer that was previously started.
description: |
Stop a timer that was started by calling [console.time](console.time), and
output the time since the timer was begun to the console in milliseconds.
If no timer exists a warning will be logged to the console.
Stop a timer that was started by calling [console.time](Global.console.time), and
output the time since the timer was begun to the console in milliseconds.
If no timer exists a warning will be logged to the console.
parameters:
- name: message
summary: The message(s) to log.
type: Object
- name: label
summary: The label to track the timer by
type: String
optional: true
default: "default"
since: 7.2.0

0 comments on commit 9df50b5

Please sign in to comment.