0.0.6 • Published 10 years ago

atom-package-config-observer v0.0.6

Weekly downloads
18
License
-
Repository
github
Last release
10 years ago

atom-package-config-observer

A small library for observing a packages config in the Atom text editor.

usage

ConfigObserver = require 'atom-package-config-observer'

class MyAtomPackage
  config: ...

  activate: ->
    # construct new ConfigObserver with your package name
    @configObserver = new ConfigObserver 'my-atom-package'
    # listen for global config changes
    @configObserver.observeGlobalConfig (config) =>
      @updateGlobalConfig config
    @configObserver.observeScopedConfig (config, editors, scopeName) =>
      # config keys not set for this scope are defaulted to global values
      # editors is an array of TextEditor instances associated with this scope
      # scopeName is a string identifying the scope (e.g. 'source.coffee')
      @updateScopedConfig config, editors, scopeName

  deactivate: ->
    @configObserver.dispose()

methods

observeGlobalConfig(callback)

Equivalent to atom.config.observe 'my-package-name', callback with the minor difference that the configuration object passed to the callback is a clone of the object returned by atom.config.observe.

observeScopedConfig(callback)

Observes TextEditor instances using atom.workspace.observeTextEditors to keep track of scopes to track. It then observes the config of each scope, disposing of the observer when no more TextEditors are associated with this scope. The callback has three arguments, see the usage section.

dispose()

Disposes of all registered observers.

configForScope(scopeName)

Returns a clone of the packages configuration object associated with the scope. When values are not set within the scope they are defaulted to the global configuration.

editorsForObservedScopes()

Returns an object with scopeNames as keys and an array of their associated TextEditors as value.

Copyright & License

© Olmo Kramer, 2015 MIT License

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago