Comparing version 1.2.0 to 1.3.0
76
index.js
@@ -1,2 +0,3 @@ | ||
// const padRight = require('pad-right') | ||
const deepDiff = require('deep-diff') | ||
const padRight = require('pad-right') | ||
const padLeft = require('pad-left') | ||
@@ -16,2 +17,7 @@ | ||
const paddings = { | ||
type: 7, | ||
actionType: 7 | ||
} | ||
// Development logger for choo | ||
@@ -30,19 +36,28 @@ // null -> obj | ||
// (obj, obj, str, str, fn) -> null | ||
function onAction (data, state, name, caller, createSend) { | ||
function onAction (data, state, name, trace, createSend) { | ||
const split = trace.split(':') | ||
const actionType = split[0].trim() | ||
const caller = split[1].trim() | ||
const line = [] | ||
colorify('lightGray', renderTime(startTime), line) | ||
colorify('gray', renderType('Action:'), line) | ||
append(`${caller} -> ${name}`, line) | ||
colorify('lightGray', renderTime(startTime) + ' ', line) | ||
colorify('gray', renderType('action') + ' ', line) | ||
colorify('gray', renderActionType(actionType) + ' ', line) | ||
colorify('default', "'" + caller + "'", line) | ||
colorify('default', '->', line) | ||
colorify('default', "'" + name + "'", line) | ||
if (console.groupCollapsed) { | ||
logGroup(line) | ||
logInner(data) | ||
logInner(name, data) | ||
console.groupEnd() | ||
} else { | ||
log(line) | ||
logInner(data) | ||
logInner(name, data) | ||
} | ||
function logInner (action) { | ||
console.log('action:', data) | ||
function logInner (name, action) { | ||
console.log('action name:', name) | ||
console.log('data:', data) | ||
} | ||
@@ -55,5 +70,5 @@ } | ||
const line = [] | ||
colorify('lightGray', renderTime(startTime), line) | ||
colorify('red', renderType('Error:'), line) | ||
append(err.message, line) | ||
colorify('lightGray', renderTime(startTime) + ' ', line) | ||
colorify('red', renderType('error') + ' ', line) | ||
colorify('default', err.message + ' ', line) | ||
@@ -77,5 +92,9 @@ if (console.groupCollapsed) { | ||
function onStateChange (data, state, prev, createSend) { | ||
const diff = deepDiff(prev, state) | ||
const inlineText = (diff.length === 1) ? 'diff' : 'diffs' | ||
const line = [] | ||
colorify('lightGray', renderTime(startTime), line) | ||
colorify('gray', renderType('State:'), line) | ||
colorify('lightGray', renderTime(startTime) + ' ', line) | ||
colorify('gray', renderType('state') + ' ', line) | ||
colorify('default', diff.length + ' ' + inlineText, line) | ||
@@ -92,4 +111,5 @@ if (console.groupCollapsed) { | ||
function logInner (prev, state) { | ||
console.log('prev', prev) | ||
console.log('prev ', prev) | ||
console.log('state', state) | ||
console.log('diff ', diff) | ||
} | ||
@@ -114,5 +134,17 @@ } | ||
function renderType (msg) { | ||
return padLeft(msg, 7, ' ') | ||
const leftPad = paddings.type | ||
const rightPad = paddings.actionType + leftPad + 2 | ||
return (msg === 'state' || msg === 'error') | ||
? padRight(padLeft(msg, leftPad, ' '), rightPad, ' ') | ||
: padLeft(msg, leftPad, ' ') | ||
} | ||
// indent action types | ||
// str -> str | ||
function renderActionType (msg) { | ||
const padding = paddings.actionType | ||
if (msg === 'subscription') msg = 'subs' | ||
return padRight(msg, padding, ' ') | ||
} | ||
// toHtml + chalk | ||
@@ -123,18 +155,10 @@ // (str, str, [str, ...str]) -> [str, str] | ||
if (!prev[0]) prev[0] = '' | ||
prev[0] = prev[0] += ' %c' + line + ' ' | ||
prev[0] = prev[0] += ' %c' + line | ||
prev.push('color: ' + colors[color]) | ||
return prev | ||
} else { | ||
return [ '%c' + line + ' ', 'color: ' + colors[color] ] | ||
return [ '%c' + line, 'color: ' + colors[color] ] | ||
} | ||
} | ||
// append to line without colorizing | ||
// (str, [str, ...str]) -> [str, str] | ||
function append (line, prev) { | ||
prev[0] = prev[0] += ' %c' + line + ' ' | ||
prev.push('color: ' + colors.default) | ||
return prev | ||
} | ||
// render the time | ||
@@ -141,0 +165,0 @@ // num -> null |
{ | ||
"name": "choo-log", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Development logger for choo", | ||
@@ -24,2 +24,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"deep-diff": "^0.3.4", | ||
"pad-left": "^2.1.0", | ||
@@ -26,0 +27,0 @@ "pad-right": "^0.2.2", |
@@ -7,2 +7,4 @@ # choo-log [![stability][0]][1] | ||
![screen capture](./screen.gif) | ||
## Usage | ||
@@ -9,0 +11,0 @@ ```js |
268481
9
198
75
4
+ Addeddeep-diff@^0.3.4
+ Addeddeep-diff@0.3.8(transitive)