Add View#observeConfig as a space-pen extension

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2012-12-14 11:08:18 -08:00
committed by Corey Johnson & Nathan Sobo
parent 97c6956e3f
commit b91c353d2b
5 changed files with 66 additions and 2 deletions

View File

@@ -50,11 +50,14 @@ class Config
observe: (keyPathString, callback) ->
keyPath = keyPathString.split('.')
value = @valueAtKeyPath(keyPath)
@on 'update', =>
updateCallback = =>
newValue = @valueAtKeyPath(keyPath)
unless newValue == value
value = newValue
callback(value)
subscription = { destroy: => @off 'update', updateCallback }
@on 'update', updateCallback
callback(value)
subscription
_.extend Config.prototype, EventEmitter

View File

@@ -13,6 +13,7 @@ RootView = require 'root-view'
Pasteboard = require 'pasteboard'
require 'jquery-extensions'
require 'underscore-extensions'
require 'space-pen-extensions'
windowAdditions =
rootViewParentSelector: 'body'