Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4
CHANGELOG | ||
v1.0.0-alpha.2 | ||
v1.0.0-alpha.4 | ||
- Support saving probe config in local storage | ||
- Doc improvements | ||
v1.0.0-alpha.3 | ||
- Fix groupEnd issue under Node.js | ||
@@ -5,0 +9,0 @@ |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.experimental = exports.Log = exports.VERSION = undefined; | ||
exports.experimental = exports.COLOR = exports.Log = exports.VERSION = undefined; | ||
@@ -27,2 +27,11 @@ var _globals = require('./lib/utils/globals'); | ||
var _color = require('./lib/utils/color'); | ||
Object.defineProperty(exports, 'COLOR', { | ||
enumerable: true, | ||
get: function get() { | ||
return _color.COLOR; | ||
} | ||
}); | ||
require('./init'); | ||
@@ -34,2 +43,4 @@ | ||
// export {default as Stats} from './lib/stats'; | ||
// Experimental exports | ||
@@ -36,0 +47,0 @@ |
@@ -32,8 +32,6 @@ 'use strict'; | ||
// import {formatTime, leftPad} from './utils/formatters'; | ||
var _globals = require('./utils/globals'); | ||
var _timeStamp = require('./utils/time-stamp'); | ||
var _timestamp = require('./utils/timestamp'); | ||
@@ -44,2 +42,6 @@ var _formatters = require('./utils/formatters'); | ||
var _localStorage = require('./utils/local-storage'); | ||
var _localStorage2 = _interopRequireDefault(_localStorage); | ||
var _autobind = require('./utils/autobind'); | ||
@@ -69,2 +71,7 @@ | ||
var DEFAULT_SETTINGS = { | ||
enabled: false, | ||
priority: 0 | ||
}; | ||
function noop() {} | ||
@@ -134,9 +141,7 @@ | ||
this.enabled = false; | ||
this.priority = 0; | ||
this.id = id; | ||
this._probe = probe; | ||
this.id = id; | ||
this._getLogFuncStore = []; | ||
this._startTs = (0, _timeStamp.getTimestamp)(); | ||
this._deltaTs = (0, _timeStamp.getTimestamp)(); | ||
this._startTs = (0, _timestamp.getTimestamp)(); | ||
this._deltaTs = (0, _timestamp.getTimestamp)(); | ||
this._lastLogFunction = null; | ||
@@ -150,4 +155,5 @@ | ||
this._storage = new _localStorage2.default('probe-' + this.id, DEFAULT_SETTINGS); | ||
(0, _autobind.autobind)(this); | ||
Object.seal(this); | ||
@@ -161,3 +167,3 @@ } | ||
this.enabled = enabled; | ||
this._storage.updateConfiguration({ enabled: enabled }); | ||
return this; | ||
@@ -168,17 +174,12 @@ } | ||
value: function setLevel(level) { | ||
this.priority = level; | ||
this._storage.updateConfiguration({ priority: level }); | ||
return this; | ||
} | ||
}, { | ||
key: 'getPriority', | ||
value: function getPriority() { | ||
return this.priority; | ||
} | ||
key: 'getTotal', | ||
// @return {Number} milliseconds, with fractions | ||
}, { | ||
key: 'getTotal', | ||
value: function getTotal() { | ||
return Number(((0, _timeStamp.getTimestamp)() - this._startTs).toPrecision(10)); | ||
return Number(((0, _timestamp.getTimestamp)() - this._startTs).toPrecision(10)); | ||
} | ||
@@ -191,3 +192,3 @@ | ||
value: function getDelta() { | ||
return Number(((0, _timeStamp.getTimestamp)() - this._deltaTs).toPrecision(10)); | ||
return Number(((0, _timestamp.getTimestamp)() - this._deltaTs).toPrecision(10)); | ||
} | ||
@@ -446,3 +447,3 @@ | ||
if (!cache[tag]) { | ||
cache[tag] = (0, _timeStamp.getTimestamp)(); | ||
cache[tag] = (0, _timestamp.getTimestamp)(); | ||
} else { | ||
@@ -567,3 +568,3 @@ return noop; | ||
// reset delta timer | ||
this._deltaTs = (0, _timeStamp.getTimestamp)(); | ||
this._deltaTs = (0, _timestamp.getTimestamp)(); | ||
return { total: total, delta: delta }; | ||
@@ -595,2 +596,16 @@ } | ||
}, { | ||
key: 'priority', | ||
set: function set(newPriority) { | ||
this._storage.updateConfiguration({ priority: newPriority }); | ||
return this; | ||
}, | ||
get: function get() { | ||
return this._storage.config.priority; | ||
} | ||
}, { | ||
key: 'enabled', | ||
get: function get() { | ||
return this._storage.config.enabled; | ||
} | ||
}]); | ||
@@ -597,0 +612,0 @@ |
@@ -24,3 +24,3 @@ 'use strict'; | ||
/* global __VERSION__ */ | ||
var VERSION = typeof '1.0.0-alpha.3' !== 'undefined' ? '1.0.0-alpha.3' : 'untranspiled source'; | ||
var VERSION = typeof '1.0.0-alpha.4' !== 'undefined' ? '1.0.0-alpha.4' : 'untranspiled source'; | ||
@@ -27,0 +27,0 @@ exports.window = window_; |
@@ -32,3 +32,3 @@ 'use strict'; | ||
/* global window */ | ||
function storageAvailable(type) { | ||
function getStorage(type) { | ||
try { | ||
@@ -45,78 +45,46 @@ var storage = window[type]; | ||
// Store keys in local storage via simple interface | ||
var LocalStorage = function () { | ||
/** | ||
* @classdesc | ||
* Store keys in local storage via simple interface | ||
* | ||
* @class | ||
* @param {Object} opts - options | ||
* @param {String} type='sessionStorage' - | ||
* 'sessionStorage' persists between reloads | ||
* 'localStorage' persists after browser is closed | ||
*/ | ||
function LocalStorage() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$type = _ref.type, | ||
type = _ref$type === undefined ? 'sessionStorage' : _ref$type; | ||
function LocalStorage(id, defaultSettings) { | ||
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'sessionStorage'; | ||
_classCallCheck(this, LocalStorage); | ||
this.storage = storageAvailable(type); | ||
if (!this.storage) { | ||
throw new Error(type + ' not available'); | ||
} | ||
this.storage = getStorage(type); | ||
this.id = id; | ||
this.config = {}; | ||
Object.assign(this.config, defaultSettings); | ||
this.loadConfiguration(); | ||
} | ||
/** | ||
* Sets string value for a key | ||
* @param {String} key - key to update | ||
* @param {String} value - string to be stored under key | ||
*/ | ||
_createClass(LocalStorage, [{ | ||
key: 'set', | ||
value: function set(key, value) { | ||
this.storage.setItem(key, value); | ||
key: 'getConfiguration', | ||
value: function getConfiguration() { | ||
return this.config; | ||
} | ||
/** | ||
* Gets string value for a key | ||
* @param {String} key - key to retrieve | ||
* @return {String} value stored under key, or undefined | ||
*/ | ||
}, { | ||
key: 'get', | ||
value: function get(key) { | ||
return this.storage.getItem(key); | ||
key: 'updateConfiguration', | ||
value: function updateConfiguration(configuration) { | ||
Object.assign(this.config, configuration); | ||
if (this.storage) { | ||
var serialized = JSON.stringify(this.config); | ||
this.storage.setItem(this.id, serialized); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Removed a key and its associated value | ||
* @param {String} key - key to remove | ||
*/ | ||
// Get config from persistent store, if available | ||
}, { | ||
key: 'remove', | ||
value: function remove(key) { | ||
this.storage.removeItem(key); | ||
} | ||
}, { | ||
key: 'getObject', | ||
value: function getObject(key) { | ||
var value = this.storage.getItem(key); | ||
try { | ||
return typeof value === 'string' ? JSON.parse(value) : {}; | ||
} catch (error) { | ||
this.remove(key); | ||
return {}; | ||
key: 'loadConfiguration', | ||
value: function loadConfiguration() { | ||
var configuration = {}; | ||
if (this.storage) { | ||
var serializedConfiguration = this.storage.getItem(this.id); | ||
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {}; | ||
} | ||
Object.assign(this.config, configuration); | ||
return this; | ||
} | ||
}, { | ||
key: 'setObject', | ||
value: function setObject(key, value) { | ||
var string = value ? JSON.stringify(value) : null; | ||
this.storage.setItem(key, string); | ||
} | ||
}]); | ||
@@ -123,0 +91,0 @@ |
@@ -35,3 +35,3 @@ 'use strict'; | ||
process: './node_modules/.bin/webpack-dev-server', | ||
parameters: ['--config', 'webpack.config.js', '--progress'], | ||
parameters: ['--config', 'webpack.config.js'], | ||
options: { maxBuffer: 5000 * 1024 } | ||
@@ -38,0 +38,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "javascript", |
@@ -6,3 +6,6 @@ import './init'; | ||
export {default as Log} from './lib/log'; | ||
export {COLOR} from './lib/utils/color'; | ||
// export {default as Stats} from './lib/stats'; | ||
// Experimental exports | ||
@@ -9,0 +12,0 @@ import {enableDOMLogging} from './lib/utils/log-to-dom'; |
@@ -24,6 +24,6 @@ // Copyright (c) 2017 Uber Technologies, Inc. | ||
import {VERSION} from './utils/globals'; | ||
import {getTimestamp} from './utils/time-stamp'; | ||
import {getTimestamp} from './utils/timestamp'; | ||
import {formatImage} from './utils/formatters'; | ||
import {addColor} from './utils/color'; | ||
// import {formatTime, leftPad} from './utils/formatters'; | ||
import LocalStorage from './utils/local-storage'; | ||
import {autobind} from './utils/autobind'; | ||
@@ -44,2 +44,7 @@ import assert from 'assert'; | ||
const DEFAULT_SETTINGS = { | ||
enabled: false, | ||
priority: 0 | ||
}; | ||
function noop() {} | ||
@@ -104,6 +109,4 @@ | ||
constructor({id, probe} = {}) { | ||
this.enabled = false; | ||
this.priority = 0; | ||
this.id = id; | ||
this._probe = probe; | ||
this.id = id; | ||
this._getLogFuncStore = []; | ||
@@ -120,4 +123,5 @@ this._startTs = getTimestamp(); | ||
this._storage = new LocalStorage(`probe-${this.id}`, DEFAULT_SETTINGS); | ||
autobind(this); | ||
Object.seal(this); | ||
@@ -127,3 +131,3 @@ } | ||
enable(enabled = true) { | ||
this.enabled = enabled; | ||
this._storage.updateConfiguration({enabled}); | ||
return this; | ||
@@ -133,10 +137,19 @@ } | ||
setLevel(level) { | ||
this.priority = level; | ||
this._storage.updateConfiguration({priority: level}); | ||
return this; | ||
} | ||
getPriority() { | ||
return this.priority; | ||
set priority(newPriority) { | ||
this._storage.updateConfiguration({priority: newPriority}); | ||
return this; | ||
} | ||
get enabled() { | ||
return this._storage.config.enabled; | ||
} | ||
get priority() { | ||
return this._storage.config.priority; | ||
} | ||
// @return {Number} milliseconds, with fractions | ||
@@ -143,0 +156,0 @@ getTotal() { |
@@ -22,3 +22,3 @@ // Copyright (c) 2017 Uber Technologies, Inc. | ||
/* global window */ | ||
function storageAvailable(type) { | ||
function getStorage(type) { | ||
try { | ||
@@ -35,60 +35,35 @@ const storage = window[type]; | ||
// Store keys in local storage via simple interface | ||
export default class LocalStorage { | ||
/** | ||
* @classdesc | ||
* Store keys in local storage via simple interface | ||
* | ||
* @class | ||
* @param {Object} opts - options | ||
* @param {String} type='sessionStorage' - | ||
* 'sessionStorage' persists between reloads | ||
* 'localStorage' persists after browser is closed | ||
*/ | ||
constructor({type = 'sessionStorage'} = {}) { | ||
this.storage = storageAvailable(type); | ||
if (!this.storage) { | ||
throw new Error(`${type} not available`); | ||
} | ||
constructor(id, defaultSettings, type = 'sessionStorage') { | ||
this.storage = getStorage(type); | ||
this.id = id; | ||
this.config = {}; | ||
Object.assign(this.config, defaultSettings); | ||
this.loadConfiguration(); | ||
} | ||
/** | ||
* Sets string value for a key | ||
* @param {String} key - key to update | ||
* @param {String} value - string to be stored under key | ||
*/ | ||
set(key, value) { | ||
this.storage.setItem(key, value); | ||
getConfiguration() { | ||
return this.config; | ||
} | ||
/** | ||
* Gets string value for a key | ||
* @param {String} key - key to retrieve | ||
* @return {String} value stored under key, or undefined | ||
*/ | ||
get(key) { | ||
return this.storage.getItem(key); | ||
updateConfiguration(configuration) { | ||
Object.assign(this.config, configuration); | ||
if (this.storage) { | ||
const serialized = JSON.stringify(this.config); | ||
this.storage.setItem(this.id, serialized); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Removed a key and its associated value | ||
* @param {String} key - key to remove | ||
*/ | ||
remove(key) { | ||
this.storage.removeItem(key); | ||
} | ||
getObject(key) { | ||
const value = this.storage.getItem(key); | ||
try { | ||
return typeof value === 'string' ? JSON.parse(value) : {}; | ||
} catch (error) { | ||
this.remove(key); | ||
return {}; | ||
// Get config from persistent store, if available | ||
loadConfiguration() { | ||
let configuration = {}; | ||
if (this.storage) { | ||
const serializedConfiguration = this.storage.getItem(this.id); | ||
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {}; | ||
} | ||
Object.assign(this.config, configuration); | ||
return this; | ||
} | ||
setObject(key, value) { | ||
const string = value ? JSON.stringify(value) : null; | ||
this.storage.setItem(key, string); | ||
} | ||
} |
@@ -28,3 +28,3 @@ // Copyright (c) 2015 - 2017 Uber Technologies, Inc. | ||
process: './node_modules/.bin/webpack-dev-server', | ||
parameters: ['--config', 'webpack.config.js', '--progress'], | ||
parameters: ['--config', 'webpack.config.js'], | ||
options: {maxBuffer: 5000 * 1024} | ||
@@ -31,0 +31,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
178519
51
2769