From ec4cf8b497835bb7c94a31d0ae367ee7c4c71562 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Feb 2014 13:05:06 -0800 Subject: [PATCH] Remove ConfigObserver This class offers little utility now that emissary exists with beefed up Subscriber and Emitter classes. --- spec/space-pen-extensions-spec.coffee | 29 --------------------------- src/config-observer.coffee | 12 ----------- src/display-buffer.coffee | 9 +++------ src/editor-view.coffee | 12 +++++------ src/space-pen-extensions.coffee | 7 +------ 5 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 src/config-observer.coffee diff --git a/spec/space-pen-extensions-spec.coffee b/spec/space-pen-extensions-spec.coffee index 28849c72c..92b95c600 100644 --- a/spec/space-pen-extensions-spec.coffee +++ b/spec/space-pen-extensions-spec.coffee @@ -11,35 +11,6 @@ describe "SpacePen extensions", -> parent = $$ -> @div() parent.append(view) - describe "View.observeConfig(keyPath, callback)", -> - observeHandler = null - - beforeEach -> - observeHandler = jasmine.createSpy("observeHandler") - view.observeConfig "foo.bar", observeHandler - expect(view.hasParent()).toBeTruthy() - - it "observes the keyPath and cancels the subscription when `.unobserveConfig()` is called", -> - expect(observeHandler).toHaveBeenCalledWith(undefined) - observeHandler.reset() - - atom.config.set("foo.bar", "hello") - - expect(observeHandler).toHaveBeenCalledWith("hello", previous: undefined) - observeHandler.reset() - - view.unobserveConfig() - - atom.config.set("foo.bar", "goodbye") - - expect(observeHandler).not.toHaveBeenCalled() - - it "unobserves when the view is removed", -> - observeHandler.reset() - parent.remove() - atom.config.set("foo.bar", "hello") - expect(observeHandler).not.toHaveBeenCalled() - describe "View.subscribe(eventEmitter, eventName, callback)", -> [emitter, eventHandler] = [] diff --git a/src/config-observer.coffee b/src/config-observer.coffee deleted file mode 100644 index 46d3c44dd..000000000 --- a/src/config-observer.coffee +++ /dev/null @@ -1,12 +0,0 @@ -Mixin = require 'mixto' - -module.exports = -class ConfigObserver extends Mixin - observeConfig: (keyPath, args...) -> - @configSubscriptions ?= {} - @configSubscriptions[keyPath] = atom.config.observe(keyPath, args...) - - unobserveConfig: -> - if @configSubscriptions? - subscription.off() for keyPath, subscription of @configSubscriptions - @configSubscriptions = null diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index c2975ba3e..06e2d397a 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -1,5 +1,5 @@ _ = require 'underscore-plus' -{Emitter, Subscriber} = require 'emissary' +{Emitter} = require 'emissary' guid = require 'guid' Serializable = require 'serializable' {Model} = require 'theorist' @@ -9,12 +9,10 @@ RowMap = require './row-map' Fold = require './fold' Token = require './token' DisplayBufferMarker = require './display-buffer-marker' -ConfigObserver = require './config-observer' module.exports = class DisplayBuffer extends Model Serializable.includeInto(this) - ConfigObserver.includeInto(this) @properties softWrap: null @@ -38,10 +36,10 @@ class DisplayBuffer extends Model @emit 'soft-wrap-changed', softWrap @updateWrappedScreenLines() - @observeConfig 'editor.preferredLineLength', callNow: false, => + @subscribe atom.config.observe 'editor.preferredLineLength', callNow: false, => @updateWrappedScreenLines() if @softWrap and atom.config.get('editor.softWrapAtPreferredLineLength') - @observeConfig 'editor.softWrapAtPreferredLineLength', callNow: false, => + @subscribe atom.config.observe 'editor.softWrapAtPreferredLineLength', callNow: false, => @updateWrappedScreenLines() if @softWrap serializeParams: -> @@ -568,7 +566,6 @@ class DisplayBuffer extends Model marker.unsubscribe() for marker in @getMarkers() @tokenizedBuffer.destroy() @unsubscribe() - @unobserveConfig() logLines: (start=0, end=@getLastRow())-> for row in [start..end] diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 39c161298..f4334843a 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -318,12 +318,12 @@ class EditorView extends View atom.project.getRepo()?.checkoutHead(path) configure: -> - @observeConfig 'editor.showLineNumbers', (showLineNumbers) => @gutter.setShowLineNumbers(showLineNumbers) - @observeConfig 'editor.showInvisibles', (showInvisibles) => @setShowInvisibles(showInvisibles) - @observeConfig 'editor.showIndentGuide', (showIndentGuide) => @setShowIndentGuide(showIndentGuide) - @observeConfig 'editor.invisibles', (invisibles) => @setInvisibles(invisibles) - @observeConfig 'editor.fontSize', (fontSize) => @setFontSize(fontSize) - @observeConfig 'editor.fontFamily', (fontFamily) => @setFontFamily(fontFamily) + @subscribe atom.config.observe 'editor.showLineNumbers', (showLineNumbers) => @gutter.setShowLineNumbers(showLineNumbers) + @subscribe atom.config.observe 'editor.showInvisibles', (showInvisibles) => @setShowInvisibles(showInvisibles) + @subscribe atom.config.observe 'editor.showIndentGuide', (showIndentGuide) => @setShowIndentGuide(showIndentGuide) + @subscribe atom.config.observe 'editor.invisibles', (invisibles) => @setInvisibles(invisibles) + @subscribe atom.config.observe 'editor.fontSize', (fontSize) => @setFontSize(fontSize) + @subscribe atom.config.observe 'editor.fontFamily', (fontFamily) => @setFontFamily(fontFamily) handleEvents: -> @on 'focus', => diff --git a/src/space-pen-extensions.coffee b/src/space-pen-extensions.coffee index abaa242cb..04e411114 100644 --- a/src/space-pen-extensions.coffee +++ b/src/space-pen-extensions.coffee @@ -1,18 +1,13 @@ _ = require 'underscore-plus' spacePen = require 'space-pen' {Subscriber} = require 'emissary' -ConfigObserver = require './config-observer' -ConfigObserver.includeInto(spacePen.View) Subscriber.includeInto(spacePen.View) jQuery = spacePen.jQuery originalCleanData = jQuery.cleanData jQuery.cleanData = (elements) -> - for element in elements - if view = jQuery(element).view() - view.unobserveConfig() - view.unsubscribe() + jQuery(element).view()?.unsubscribe() for element in elements originalCleanData(elements) tooltipDefaults =