Skip to content

Commit fdf9c15

Browse files
committed
fix(events): Change conditions for disabling listeners (fixes #373)
Problem: Any truthy value returned from an event listener will signal the emitter to disable the listener. Solution: Only disable the listeners when the returned value is both truthy, and of type boolean.
1 parent 989fc91 commit fdf9c15

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lua/diffview/events.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ local function filter_call(listeners, event, args)
169169
for i = 1, #listeners do
170170
local cur = listeners[i]
171171
local ret = cur.call(event, args)
172+
local discard = (type(ret) == "boolean" and ret)
173+
or cur.type == "once"
174+
or cur.type == "any_once"
172175

173-
if not (cur.type == "once" or cur.type == "any_once") and not ret then
174-
result[#result + 1] = cur
175-
end
176+
if not discard then result[#result + 1] = cur end
176177

177178
if not event.propagate then
178179
for j = i + 1, #listeners do result[j] = listeners[j] end

0 commit comments

Comments
 (0)