Skip to content

Commit

Permalink
fix: #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Rodionov committed Sep 29, 2015
1 parent 694daf2 commit d16f808
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 20 deletions.
181 changes: 180 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,180 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.reduxLogger=t():e.reduxLogger=t()}(this,function(){return function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){o(1),e.exports=o(1)},function(e,t){"use strict";function o(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return function(t){var o=t.getState;return function(t){return function(c){var i=e.level,u=e.logger,f=e.collapsed,d=e.predicate,a=e.duration,l=void 0===a?!1:a,p=e.timestamp,s=void 0===p?!0:p,g=e.transformer,v=void 0===g?function(e){return e}:g,x=e.actionTransformer,m=void 0===x?function(e){return e}:x,y=u||window.console;if("undefined"==typeof y)return t(c);if("function"==typeof d&&!d(o,c))return t(c);var w=r.now(),b=v(o()),h=t(c),E=r.now()-w,F=v(o()),j=new Date,A="function"==typeof f?f(o,c):f,C=s?" @ "+j.getHours()+":"+n(j.getMinutes())+":"+n(j.getSeconds()):"",D=l?" in "+E.toFixed(2)+" ms":"",L=m(c),M="action "+L.type+C+D;try{A?y.groupCollapsed(M):y.group(M)}catch(S){y.log(M)}i?(y[i]("%c prev state","color: #9E9E9E; font-weight: bold",b),y[i]("%c action","color: #03A9F4; font-weight: bold",c),y[i]("%c next state","color: #4CAF50; font-weight: bold",F)):(y.log("%c prev state","color: #9E9E9E; font-weight: bold",b),y.log("%c action","color: #03A9F4; font-weight: bold",c),y.log("%c next state","color: #4CAF50; font-weight: bold",F));try{y.groupEnd()}catch(S){y.log("—— log end ——")}return h}}}}Object.defineProperty(t,"__esModule",{value:!0});var n=function(e){return("0"+e).slice(-2)},r="undefined"!=typeof performance&&"function"==typeof performance.now?performance:Date;t["default"]=o,e.exports=t["default"]}])});
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["reduxLogger"] = factory();
else
root["reduxLogger"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

__webpack_require__(1);
module.exports = __webpack_require__(1);


/***/ },
/* 1 */
/***/ function(module, exports) {

"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
var pad = function pad(num) {
return ("0" + num).slice(-2);
};

// Use the new performance api to get better precision if available
var timer = typeof performance !== "undefined" && typeof performance.now === "function" ? performance : Date;

/**
* Creates logger with followed options
*
* @namespace
* @property {object} options - options for logger
* @property {string} options.level - console[level]
* @property {object} options.logger - implementation of the `console` API.
* @property {boolean} options.collapsed - is group collapsed?
* @property {boolean} options.predicate - condition which resolves logger behavior
* @property {bool} options.duration - print duration of each action?
* @property {bool} options.timestamp - print timestamp with each action?
* @property {function} options.transformer - transform state before print
* @property {function} options.actionTransformer - transform action before print
*/

function createLogger() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

return function (_ref) {
var getState = _ref.getState;
return function (next) {
return function (action) {
var level = options.level;
var logger = options.logger;
var collapsed = options.collapsed;
var predicate = options.predicate;
var _options$duration = options.duration;
var duration = _options$duration === undefined ? false : _options$duration;
var _options$timestamp = options.timestamp;
var timestamp = _options$timestamp === undefined ? true : _options$timestamp;
var _options$transformer = options.transformer;
var transformer = _options$transformer === undefined ? function (state) {
return state;
} : _options$transformer;
var _options$actionTransformer = options.actionTransformer;
var actionTransformer = _options$actionTransformer === undefined ? function (actn) {
return actn;
} : _options$actionTransformer;

var console = logger || window.console;

// exit if console undefined
if (typeof console === "undefined") {
return next(action);
}

// exit early if predicate function returns false
if (typeof predicate === "function" && !predicate(getState, action)) {
return next(action);
}

var started = timer.now();
var prevState = transformer(getState());

var returnValue = next(action);
var took = timer.now() - started;

var nextState = transformer(getState());

// formatters
var time = new Date();
var isCollapsed = typeof collapsed === "function" ? collapsed(getState, action) : collapsed;

var formattedTime = timestamp ? " @ " + time.getHours() + ":" + pad(time.getMinutes()) + ":" + pad(time.getSeconds()) : "";
var formattedDuration = duration ? " in " + took.toFixed(2) + " ms" : "";
var formattedAction = actionTransformer(action);
var message = "action " + formattedAction.type + formattedTime + formattedDuration;

// render
try {
isCollapsed ? console.groupCollapsed(message) : console.group(message);
} catch (e) {
console.log(message);
}

if (level) {
console[level]("%c prev state", "color: #9E9E9E; font-weight: bold", prevState);
console[level]("%c action", "color: #03A9F4; font-weight: bold", formattedAction);
console[level]("%c next state", "color: #4CAF50; font-weight: bold", nextState);
} else {
console.log("%c prev state", "color: #9E9E9E; font-weight: bold", prevState);
console.log("%c action", "color: #03A9F4; font-weight: bold", formattedAction);
console.log("%c next state", "color: #4CAF50; font-weight: bold", nextState);
}

try {
console.groupEnd();
} catch (e) {
console.log("—— log end ——");
}

return returnValue;
};
};
};
}

exports["default"] = createLogger;
module.exports = exports["default"];

/***/ }
/******/ ])
});
;
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions example/dist/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"babel-plugin-react-transform": "^1.1.0",
"css-loader": "^0.19.0",
"express": "^4.13.3",
"node-sass": "^3.3.3",
"react-transform-hmr": "^1.0.0",
"sass-loader": "^2.0.1",
"style-loader": "^0.12.4",
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ function createLogger() {

if (level) {
console[level]("%c prev state", "color: #9E9E9E; font-weight: bold", prevState);
console[level]("%c action", "color: #03A9F4; font-weight: bold", action);
console[level]("%c action", "color: #03A9F4; font-weight: bold", formattedAction);
console[level]("%c next state", "color: #4CAF50; font-weight: bold", nextState);
} else {
console.log("%c prev state", "color: #9E9E9E; font-weight: bold", prevState);
console.log("%c action", "color: #03A9F4; font-weight: bold", action);
console.log("%c action", "color: #03A9F4; font-weight: bold", formattedAction);
console.log("%c next state", "color: #4CAF50; font-weight: bold", nextState);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "redux-logger",
"version": "2.0.0",
"version": "2.0.1",
"description": "Logger for redux",
"main": "lib/index.js",
"scripts": {
"test": "npm run lint",
"clean": "rimraf build",
"lint": "eslint src",
"build:lib": "babel src --out-dir lib",
"build:umd": "LIBRARY_NAME=reduxLogger webpack -p src/index.js dist/index.js --config webpack.config.production.js",
"build:umd": "LIBRARY_NAME=reduxLogger webpack src/index.js dist/index.js --config webpack.config.production.js",
"build:umd:min": "LIBRARY_NAME=reduxLogger webpack -p src/index.js dist/index.min.js --config webpack.config.development.js",
"build:example": "webpack -p --config example/webpack.config.production.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min && npm run build:example",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ function createLogger(options = {}) {

if (level) {
console[level](`%c prev state`, `color: #9E9E9E; font-weight: bold`, prevState);
console[level](`%c action`, `color: #03A9F4; font-weight: bold`, action);
console[level](`%c action`, `color: #03A9F4; font-weight: bold`, formattedAction);
console[level](`%c next state`, `color: #4CAF50; font-weight: bold`, nextState);
} else {
console.log(`%c prev state`, `color: #9E9E9E; font-weight: bold`, prevState);
console.log(`%c action`, `color: #03A9F4; font-weight: bold`, action);
console.log(`%c action`, `color: #03A9F4; font-weight: bold`, formattedAction);
console.log(`%c next state`, `color: #4CAF50; font-weight: bold`, nextState);
}

Expand Down
6 changes: 0 additions & 6 deletions webpack.config.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ config.plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false
}
})
];

module.exports = config;

0 comments on commit d16f808

Please sign in to comment.