From 73f66f25e6b8e5b5b8456074ad4fa79ba1d3ca4d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 4 Jan 2015 16:19:14 +0000 Subject: Modes; revise InsertMode as two classes. --- lib/handler_stack.coffee | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'lib/handler_stack.coffee') diff --git a/lib/handler_stack.coffee b/lib/handler_stack.coffee index 17e4844b..0a34087f 100644 --- a/lib/handler_stack.coffee +++ b/lib/handler_stack.coffee @@ -40,17 +40,12 @@ class HandlerStack true remove: (id = @currentId) -> - if 0 < @stack.length and @stack[@stack.length-1].id == id - # A common case is to remove the handler at the top of the stack. And we can do this very efficiently. - # Tests suggest that this case arises more than half of the time. - @stack.pop().id = null - else - # Otherwise, we'll build a new stack. This is better than splicing the existing stack since that can - # interfere with concurrent bubbleEvents. - @stack = @stack.filter (handler) -> - # Mark this handler as removed (for any active bubbleEvent call). - handler.id = null if handler.id == id - handler?.id? + # This is more expense than splicing @stack, but better because splicing can interfere with concurrent + # bubbleEvents. + @stack = @stack.filter (handler) -> + # Mark this handler as removed (to notify any concurrent bubbleEvent call). + if handler.id == id then handler.id = null + handler?.id? # The handler stack handles chrome events (which may need to be suppressed) and internal (fake) events. # This checks whether that the event at hand is a chrome event. -- cgit v1.2.3