File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 5959 "node-fetch" : " ^1.3.2" ,
6060 "npm-run-all" : " ^1.2.8" ,
6161 "power-assert" : " ^1.0.0" ,
62+ "redux" : " ^3.5.2" ,
6263 "remark" : " ^4.1.1" ,
6364 "stemming-x-keywords" : " ^1.0.3" ,
6465 "textlint" : " ^6.1.0" ,
Original file line number Diff line number Diff line change 1+ // LICENSE : MIT
2+ "use strict" ;
3+ const defaultOptions = {
4+ // default: logger use console API
5+ logger : console
6+ } ;
7+ /**
8+ * create logger middleware
9+ * @param {{logger: *} } options
10+ * @returns {Function } middleware function
11+ */
12+ export default function createLogger ( options = defaultOptions ) {
13+ const logger = options . logger || defaultOptions . logger ;
14+ return store => next => action => {
15+ logger . log ( action ) ;
16+ return next ( action ) ;
17+ } ;
18+ }
Original file line number Diff line number Diff line change 1+ // LICENSE : MIT
2+ "use strict" ;
3+ const assert = require ( "power-assert" ) ;
4+ import { createStore , applyMiddleware } from "redux" ;
5+ import createLogger from "../../src/redux/action-logger" ;
6+ const initialState = { } ;
7+ const reducer = ( state = initialState , action ) => state ;
8+
9+ describe ( "logger-test" , function ( ) {
10+ let store , dispatch , logs ;
11+ beforeEach ( ( ) => {
12+ logs = [ ] ;
13+ const con = {
14+ log ( message ) {
15+ logs . push ( message ) ;
16+ }
17+ } ;
18+ const middleware = createLogger ( {
19+ logger : con
20+ } ) ;
21+ store = applyMiddleware ( middleware ) ( createStore ) ( reducer ) ;
22+ dispatch = store . dispatch ;
23+ } ) ;
24+ afterEach ( ( ) => {
25+ logs . length = 0 ;
26+ } ) ;
27+ it ( "should output log" , function ( ) {
28+ const action = { type : "FOO" } ;
29+ dispatch ( action ) ;
30+ assert . deepEqual ( logs , [ action ] ) ;
31+ } ) ;
32+ } ) ;
You can’t perform that action at this time.
0 commit comments