Skip to content

Instantly share code, notes, and snippets.

@craftzdog
Last active July 23, 2017 00:54
Show Gist options
  • Save craftzdog/e44aa31281d4679865014ab04c301efc to your computer and use it in GitHub Desktop.
Save craftzdog/e44aa31281d4679865014ab04c301efc to your computer and use it in GitHub Desktop.
Config settings for plugins

Defining settings for your plugin

Define a schema under a config key in your plugin main.

module.exports = {
  config: {
    someStr: {
      title: 'host',
      description: 'plantuml server',
      type: 'string',
      default: 'localhost'
    },
    enableThing: {
      title: 'enable thing',
      type: 'boolean',
      default: false
    },
    thingVolume: {
      title: 'thing volume',
      type: 'integer',
      default: 5,
      minimum: 1,
      maximum: 11
    }
  },

  activate () {
    // ...
  }
}

Getting and setting config settings

inkdrop.config.get('my-package.myKey') # -> 'defaultValue' 
 
inkdrop.config.set('my-package.myKey', 'value')
inkdrop.config.get('my-package.myKey') # -> 'value' 

You may want to watch for changes. Use ::observe to catch changes to the setting.

inkdrop.config.set('my-package.myKey', 'value')
inkdrop.config.observe('my-package.myKey', (newValue) => {
  // `observe` calls immediately and every time the value is changed 
  console.log('My configuration changed:', newValue)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment