Skip to content

Commit a02fc3a

Browse files
authored
Enhance the JSDoc (#1)
1 parent a1cacb8 commit a02fc3a

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

conditional-breakpoint.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
(function(window) {
1+
(function (window) {
22
'use strict';
33

4-
var getHandler = function(eventName) {
5-
/**
6-
* @param {Function} conditionCallback
7-
* @param {Function} actionCallback
8-
*/
9-
return function(conditionCallback, actionCallback) {
10-
var ready = true;
4+
/**
5+
* @template {'resize'|'scroll'} E
6+
*
7+
* @param {E} eventName
8+
*
9+
* @return {
10+
* (
11+
* condition: (this: Window) => boolean,
12+
* action: (this: Window, ready: boolean, event: GlobalEventHandlersEventMap[E]) => void
13+
* ) => void
14+
* }
15+
*/
16+
function getHandler(eventName) {
17+
return function(condition, action) {
18+
let ready = true;
1119

12-
window.addEventListener(eventName, function() {
13-
if (conditionCallback.call(this)) {
20+
window.addEventListener(eventName, function (event) {
21+
if (condition.call(this)) {
1422
if (ready) {
15-
actionCallback.call(this, ready);
23+
action.call(this, ready, event);
1624
ready = !ready;
1725
}
18-
}
19-
else {
26+
} else {
2027
if (!ready) {
21-
actionCallback.call(this, ready);
28+
action.call(this, ready, event);
2229
ready = !ready;
2330
}
2431
}
2532
});
2633
};
27-
};
34+
}
2835

2936
window.conditionalBreakpoint = Object.create(null);
3037
window.conditionalBreakpoint.resize = getHandler('resize');

0 commit comments

Comments
 (0)