UNPKG

rxact-debugger

Version:

Debugger for rxact

65 lines (56 loc) 1.69 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var BOLD = 'font-weight:bold;'; var UNDERLINE = 'text-decoration:underline;'; var COLOR = function COLOR(color) { return 'color:' + color + ';'; }; var toObject = function toObject(state) { if (state.toJS) { return state.toJS(); } return state; }; var operatorLogger = exports.operatorLogger = function operatorLogger(type) { var logger = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'log'; var streamName = arguments[2]; var operatorName = arguments[3]; var prefix = ''; var action = ''; var color = ''; switch (type) { case 'emitter': { prefix = 'STATE '; action = 'updated'; color = '#3dbd7d'; break; } case 'dispose': { prefix = 'DISPOSE '; action = 'disposed'; color = '#f04134'; break; } default: { prefix = 'OPERATOR'; action = 'called '; color = '#948aec'; break; } } console[logger]('%c' + prefix + ' %c ' + action + ' %c' + streamName + '->' + operatorName, BOLD + COLOR(color), BOLD + COLOR('#108ee9'), UNDERLINE + BOLD + COLOR('#5a5a5a')); }; var stateLog = function stateLog(color, content, state) { console.log('%c' + content, COLOR(color) + BOLD, state); }; var emitterLogger = exports.emitterLogger = function emitterLogger(streamName, emitterName, prevState, nextState) { operatorLogger('emitter', 'groupCollapsed', streamName, emitterName); stateLog('#5a5a5a', 'prevState:', toObject(prevState)); stateLog('#ffce3d', 'nextState:', toObject(nextState)); console.groupEnd(); };