Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
9126b3c6
Commit
9126b3c6
authored
Oct 17, 2016
by
Sean Hammond
Committed by
GitHub
Oct 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #146 from hypothesis/debug-middleware
Add application state debugging utility
parents
623c607b
4c0bac78
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
annotation-ui.js
h/static/scripts/annotation-ui.js
+3
-0
debug-middleware.js
h/static/scripts/reducers/debug-middleware.js
+40
-0
debug-middleware-test.js
h/static/scripts/reducers/test/debug-middleware-test.js
+43
-0
No files found.
h/static/scripts/annotation-ui.js
View file @
9126b3c6
...
@@ -43,6 +43,8 @@ var sessionReducer = require('./reducers/session');
...
@@ -43,6 +43,8 @@ var sessionReducer = require('./reducers/session');
var
viewerReducer
=
require
(
'./reducers/viewer'
);
var
viewerReducer
=
require
(
'./reducers/viewer'
);
var
util
=
require
(
'./reducers/util'
);
var
util
=
require
(
'./reducers/util'
);
var
debugMiddleware
=
require
(
'./reducers/debug-middleware'
);
/**
/**
* Redux middleware which triggers an Angular change-detection cycle
* Redux middleware which triggers an Angular change-detection cycle
* if no cycle is currently in progress.
* if no cycle is currently in progress.
...
@@ -75,6 +77,7 @@ module.exports = function ($rootScope, settings) {
...
@@ -75,6 +77,7 @@ module.exports = function ($rootScope, settings) {
// This is used to implement actions which have side effects or are
// This is used to implement actions which have side effects or are
// asynchronous (see https://github.com/gaearon/redux-thunk#motivation)
// asynchronous (see https://github.com/gaearon/redux-thunk#motivation)
thunk
,
thunk
,
debugMiddleware
,
angularDigestMiddleware
.
bind
(
null
,
$rootScope
)
angularDigestMiddleware
.
bind
(
null
,
$rootScope
)
);
);
var
store
=
redux
.
createStore
(
reducers
.
update
,
reducers
.
init
(
settings
),
var
store
=
redux
.
createStore
(
reducers
.
update
,
reducers
.
init
(
settings
),
...
...
h/static/scripts/reducers/debug-middleware.js
0 → 100644
View file @
9126b3c6
'use strict'
;
/**
* A debug utility that prints information about internal application state
* changes to the console.
*
* Debugging is enabled by setting `window.debug` to a truthy value.
*
* When enabled, every action that changes application state will be printed
* to the console, along with the application state before and after the action
* was handled.
*/
function
debugMiddleware
(
store
)
{
/* eslint-disable no-console */
var
serial
=
0
;
return
function
(
next
)
{
return
function
(
action
)
{
if
(
!
window
.
debug
)
{
next
(
action
);
return
;
}
++
serial
;
var
groupTitle
=
action
.
type
+
' ('
+
serial
.
toString
()
+
')'
;
console
.
group
(
groupTitle
);
console
.
log
(
'Prev State:'
,
store
.
getState
());
console
.
log
(
'Action:'
,
action
);
next
(
action
);
console
.
log
(
'Next State:'
,
store
.
getState
());
console
.
groupEnd
(
groupTitle
);
};
};
/* eslint-enable no-console */
}
module
.
exports
=
debugMiddleware
;
h/static/scripts/reducers/test/debug-middleware-test.js
0 → 100644
View file @
9126b3c6
'use strict'
;
/* eslint-disable no-console */
var
redux
=
require
(
'redux'
);
var
debugMiddleware
=
require
(
'../debug-middleware'
);
function
id
(
state
)
{
return
state
;
}
describe
(
'debug middleware'
,
function
()
{
var
store
;
beforeEach
(
function
()
{
sinon
.
stub
(
console
,
'log'
);
sinon
.
stub
(
console
,
'group'
);
sinon
.
stub
(
console
,
'groupEnd'
);
var
enhancer
=
redux
.
applyMiddleware
(
debugMiddleware
);
store
=
redux
.
createStore
(
id
,
{},
enhancer
);
});
afterEach
(
function
()
{
console
.
log
.
restore
();
console
.
group
.
restore
();
console
.
groupEnd
.
restore
();
delete
window
.
debug
;
});
it
(
'logs app state changes when "window.debug" is truthy'
,
function
()
{
window
.
debug
=
true
;
store
.
dispatch
({
type
:
'SOMETHING_HAPPENED'
});
assert
.
called
(
console
.
log
);
});
it
(
'logs nothing when "window.debug" is falsey'
,
function
()
{
store
.
dispatch
({
type
:
'SOMETHING_HAPPENED'
});
assert
.
notCalled
(
console
.
log
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment