From 741bc131353eb856022d66252309de23a0873fc7 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 21 Mar 2016 12:30:57 +0000 Subject: Simplify singleton handling. While working on the visual-mode code, it became apparent that our current "singleton" implementation is unnecessarily complicated. This simplifies it. The keys are now required to be strings. (Previously, they could be any object; which meant we needed to gove objects an identity. All of which was complicated.) --- content_scripts/mode.coffee | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'content_scripts/mode.coffee') diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 205b8288..d5775ad7 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -109,15 +109,14 @@ class Mode "scroll": (event) => @alwaysContinueBubbling => @exit event # Some modes are singletons: there may be at most one instance active at any time. A mode is a singleton - # if @options.singleton is truthy. The value of @options.singleton should be the key which is intended to - # be unique. New instances deactivate existing instances with the same key. + # if @options.singleton is set. The value of @options.singleton should be the key which is intended to be + # unique. New instances deactivate existing instances with the same key. if @options.singleton - do => - singletons = Mode.singletons ||= {} - key = Utils.getIdentity @options.singleton - @onExit -> delete singletons[key] - @deactivateSingleton @options.singleton - singletons[key] = this + singletons = Mode.singletons ||= {} + key = @options.singleton + @onExit -> delete singletons[key] + singletons[key]?.exit() + singletons[key] = this # If @options.passInitialKeyupEvents is set, then we pass initial non-printable keyup events to the page # or to other extensions (because the corresponding keydown events were passed). This is used when @@ -182,9 +181,6 @@ class Mode @modeIsActive = false @setIndicator() - deactivateSingleton: (singleton) -> - Mode.singletons?[Utils.getIdentity singleton]?.exit() - # Shorthand for an otherwise long name. This wraps a handler with an arbitrary return value, and always # yields @continueBubbling instead. This simplifies handlers if they always continue bubbling (a common # case), because they do not need to be concerned with the value they yield. -- cgit v1.2.3