Merge pull request #1519 from atom/ks-remove-config-observer

Remove ConfigObserver
This commit is contained in:
Kevin Sawicki 2014-02-06 14:06:09 -08:00
commit ff1440be26
7 changed files with 16 additions and 66 deletions

View File

@ -4,7 +4,6 @@ module.exports =
_: require 'underscore-plus'
BufferedNodeProcess: require '../src/buffered-node-process'
BufferedProcess: require '../src/buffered-process'
ConfigObserver: require '../src/config-observer'
Directory: require '../src/directory'
File: require '../src/file'
fs: require 'fs-plus'

View File

@ -76,7 +76,7 @@
"exception-reporting": "0.13.0",
"feedback": "0.22.0",
"find-and-replace": "0.81.0",
"fuzzy-finder": "0.32.0",
"fuzzy-finder": "0.33.0",
"gists": "0.16.0",
"git-diff": "0.23.0",
"github-sign-in": "0.18.0",
@ -88,10 +88,10 @@
"markdown-preview": "0.25.1",
"metrics": "0.24.0",
"package-generator": "0.25.0",
"release-notes": "0.17.0",
"settings-view": "0.68.0",
"release-notes": "0.18.0",
"settings-view": "0.69.0",
"snippets": "0.24.0",
"spell-check": "0.22.0",
"spell-check": "0.23.0",
"status-bar": "0.32.0",
"styleguide": "0.22.0",
"symbols-view": "0.31.0",
@ -99,12 +99,12 @@
"terminal": "0.27.0",
"timecop": "0.13.0",
"to-the-hubs": "0.19.0",
"tree-view": "0.67.0",
"tree-view": "0.68.0",
"update-package-dependencies": "0.2.0",
"visual-bell": "0.6.0",
"welcome": "0.4.0",
"whitespace": "0.10.0",
"wrap-guide": "0.12.0",
"wrap-guide": "0.13.0",
"language-c": "0.2.0",
"language-clojure": "0.1.0",
"language-coffee-script": "0.6.0",

View File

@ -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] = []

View File

@ -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

View File

@ -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]

View File

@ -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', =>

View File

@ -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 =