diff options
| author | Stephen Blott | 2016-03-21 12:30:57 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-21 12:31:00 +0000 | 
| commit | 741bc131353eb856022d66252309de23a0873fc7 (patch) | |
| tree | dc5f2453155f4ef87c4eeb71247623997fb621cc /content_scripts/mode.coffee | |
| parent | 8783569983d8b3634b1b1eed9b6560dbea5698ab (diff) | |
| download | vimium-741bc131353eb856022d66252309de23a0873fc7.tar.bz2 | |
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.)
Diffstat (limited to 'content_scripts/mode.coffee')
| -rw-r--r-- | content_scripts/mode.coffee | 18 | 
1 files changed, 7 insertions, 11 deletions
| 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. | 
