Skip to content

Commit e4053be

Browse files
xzhan96rogerwang
authored andcommitted
Adds the logic when removeAllListeners has no parameter
fixed nwjs#5649
1 parent e0f620a commit e4053be

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

docs/References/Window.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ Execute a piece of JavaScript in the frame.
427427

428428
Load and execute the compiled binary in the frame. See [Protect JavaScript Source Code](../For Users/Advanced/Protect JavaScript Source Code.md).
429429

430+
## win.removeAllListeners([eventName])
431+
432+
Removes all listeners, or those of the specified `eventName`.
433+
430434
## Event: close
431435

432436
The `close` event is a special event that will affect the result of the `Window.close()` function. If developer is listening to the `close` event of a window, the `Window.close()` emit the `close` event without closing the window.

src/resources/api_nw_window.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ nw_binding.registerCustomHook(function(bindingsAPI) {
339339
};
340340

341341
NWWindow.prototype.removeAllListeners = function (event) {
342+
if (arguments.length === 0) {
343+
var obj = Object.assign({}, appWinEventsMap, nwWinEventsMap, nwWrapEventsMap);
344+
var keys = Object.keys(obj);
345+
for (var i = 0, key; i < keys.length; ++i) {
346+
key = keys[i];
347+
this.removeAllListeners(key);
348+
}
349+
return this;
350+
}
342351
nwNatives.callInWindow(bgPage, "__nw_remove_all_listeners", this, event);
343352
if (appWinEventsMap.hasOwnProperty(event)) {
344353
for (let l of this.appWindow[appWinEventsMap[event]].getListeners()) {

0 commit comments

Comments
 (0)