Mailspring/packages/client-app/docs/classes/Config.html

1891 lines
55 KiB
HTML

<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Config · Nylas Mail Plugin SDK</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.2">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="Contenteditable.html" />
<link rel="prev" href="Color.html" />
<link rel="shortcut icon" href='../img/favicon.png' type="image/x-icon">
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" >
<span>
Nylas Mail SDK Guides
</span>
</li>
<li class="chapter " data-level="1.2" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../guides/GettingStarted.html">
<a href="../guides/GettingStarted.html">
Getting Started
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../guides/GettingStarted-2.html">
<a href="../guides/GettingStarted-2.html">
Getting Started Part 2
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../guides/PackageOverview.html">
<a href="../guides/PackageOverview.html">
Building a Package
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../guides/InterfaceConcepts.html">
<a href="../guides/InterfaceConcepts.html">
Interface Concepts
</a>
</li>
<li class="chapter " data-level="1.7" data-path="../guides/React.html">
<a href="../guides/React.html">
UI Components
</a>
</li>
<li class="chapter " data-level="1.8" data-path="../guides/Architecture.html">
<a href="../guides/Architecture.html">
Application Architecture
</a>
</li>
<li class="chapter " data-level="1.9" data-path="../guides/Debugging.html">
<a href="../guides/Debugging.html">
Debugging Nylas Mail
</a>
</li>
<li class="chapter " data-level="1.10" data-path="../guides/Database.html">
<a href="../guides/Database.html">
Accessing the Database
</a>
</li>
<li class="chapter " data-level="1.11" data-path="../guides/ComposerExtensions.html">
<a href="../guides/ComposerExtensions.html">
Extending the Composer
</a>
</li>
<li class="chapter " data-level="1.12" data-path="../guides/WritingSpecs.html">
<a href="../guides/WritingSpecs.html">
Writing Tests
</a>
</li>
<li class="chapter " data-level="1.13" data-path="../guides/IntegrationTesting.html">
<a href="../guides/IntegrationTesting.html">
Integration Testing
</a>
</li>
<li class="chapter " data-level="1.14" data-path="../guides/Windows.html">
<a href="../guides/Windows.html">
Developing on Windows
</a>
</li>
<li class="chapter " data-level="1.15" data-path="../guides/FAQ.html">
<a href="../guides/FAQ.html">
FAQ
</a>
</li>
<li class="header">Full Class Reference</li>
<li class="chapter " data-level="2.1" >
<span>
General
</span>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="Actions.html">
<a href="Actions.html">
Actions
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="BufferedProcess.html">
<a href="BufferedProcess.html">
BufferedProcess
</a>
</li>
<li class="chapter " data-level="2.1.3" data-path="ChangeFolderTask.html">
<a href="ChangeFolderTask.html">
ChangeFolderTask
</a>
</li>
<li class="chapter " data-level="2.1.4" data-path="ChangeLabelsTask.html">
<a href="ChangeLabelsTask.html">
ChangeLabelsTask
</a>
</li>
<li class="chapter " data-level="2.1.5" data-path="ChangeMailTask.html">
<a href="ChangeMailTask.html">
ChangeMailTask
</a>
</li>
<li class="chapter " data-level="2.1.6" data-path="Color.html">
<a href="Color.html">
Color
</a>
</li>
<li class="chapter active" data-level="2.1.7" data-path="Config.html">
<a href="Config.html">
Config
</a>
</li>
<li class="chapter " data-level="2.1.8" data-path="Contenteditable.html">
<a href="Contenteditable.html">
Contenteditable
</a>
</li>
<li class="chapter " data-level="2.1.9" data-path="KeyCommandsRegion.html">
<a href="KeyCommandsRegion.html">
KeyCommandsRegion
</a>
</li>
<li class="chapter " data-level="2.1.10" data-path="NylasEnvConstructor.html">
<a href="NylasEnvConstructor.html">
NylasEnvConstructor
</a>
</li>
<li class="chapter " data-level="2.1.11" data-path="QueryResultSet.html">
<a href="QueryResultSet.html">
QueryResultSet
</a>
</li>
<li class="chapter " data-level="2.1.12" data-path="QuerySubscriptionPool.html">
<a href="QuerySubscriptionPool.html">
QuerySubscriptionPool
</a>
</li>
<li class="chapter " data-level="2.1.13" data-path="StyleManager.html">
<a href="StyleManager.html">
StyleManager
</a>
</li>
<li class="chapter " data-level="2.1.14" data-path="Task.html">
<a href="Task.html">
Task
</a>
</li>
<li class="chapter " data-level="2.1.15" data-path="TaskQueueStatusStore.html">
<a href="TaskQueueStatusStore.html">
TaskQueueStatusStore
</a>
</li>
<li class="chapter " data-level="2.1.16" data-path="ThemeManager.html">
<a href="ThemeManager.html">
ThemeManager
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" >
<span>
Component Kit
</span>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="EventedIFrame.html">
<a href="EventedIFrame.html">
EventedIFrame
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="Flexbox.html">
<a href="Flexbox.html">
Flexbox
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="InjectedComponent.html">
<a href="InjectedComponent.html">
InjectedComponent
</a>
</li>
<li class="chapter " data-level="2.2.4" data-path="InjectedComponentSet.html">
<a href="InjectedComponentSet.html">
InjectedComponentSet
</a>
</li>
<li class="chapter " data-level="2.2.5" data-path="Menu.html">
<a href="Menu.html">
Menu
</a>
</li>
<li class="chapter " data-level="2.2.6" data-path="MenuItem.html">
<a href="MenuItem.html">
MenuItem
</a>
</li>
<li class="chapter " data-level="2.2.7" data-path="MenuNameEmailItem.html">
<a href="MenuNameEmailItem.html">
MenuNameEmailItem
</a>
</li>
<li class="chapter " data-level="2.2.8" data-path="MultiselectActionBar.html">
<a href="MultiselectActionBar.html">
MultiselectActionBar
</a>
</li>
<li class="chapter " data-level="2.2.9" data-path="MultiselectList.html">
<a href="MultiselectList.html">
MultiselectList
</a>
</li>
<li class="chapter " data-level="2.2.10" data-path="ResizableRegion.html">
<a href="ResizableRegion.html">
ResizableRegion
</a>
</li>
<li class="chapter " data-level="2.2.11" data-path="RetinaImg.html">
<a href="RetinaImg.html">
RetinaImg
</a>
</li>
<li class="chapter " data-level="2.2.12" data-path="Spinner.html">
<a href="Spinner.html">
Spinner
</a>
</li>
<li class="chapter " data-level="2.2.13" data-path="UnsafeComponent.html">
<a href="UnsafeComponent.html">
UnsafeComponent
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.3" >
<span>
Extensions
</span>
<ul class="articles">
<li class="chapter " data-level="2.3.1" data-path="ComposerExtension.html">
<a href="ComposerExtension.html">
ComposerExtension
</a>
</li>
<li class="chapter " data-level="2.3.2" data-path="ContenteditableExtension.html">
<a href="ContenteditableExtension.html">
ContenteditableExtension
</a>
</li>
<li class="chapter " data-level="2.3.3" data-path="DraftStoreExtension.html">
<a href="DraftStoreExtension.html">
DraftStoreExtension
</a>
</li>
<li class="chapter " data-level="2.3.4" data-path="MessageStoreExtension.html">
<a href="MessageStoreExtension.html">
MessageStoreExtension
</a>
</li>
<li class="chapter " data-level="2.3.5" data-path="MessageViewExtension.html">
<a href="MessageViewExtension.html">
MessageViewExtension
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.4" >
<span>
Models
</span>
<ul class="articles">
<li class="chapter " data-level="2.4.1" data-path="Contact.html">
<a href="Contact.html">
Contact
</a>
</li>
<li class="chapter " data-level="2.4.2" data-path="Message.html">
<a href="Message.html">
Message
</a>
</li>
<li class="chapter " data-level="2.4.3" data-path="Model.html">
<a href="Model.html">
Model
</a>
</li>
<li class="chapter " data-level="2.4.4" data-path="Thread.html">
<a href="Thread.html">
Thread
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.5" >
<span>
Stores
</span>
<ul class="articles">
<li class="chapter " data-level="2.5.1" data-path="AccountStore.html">
<a href="AccountStore.html">
AccountStore
</a>
</li>
<li class="chapter " data-level="2.5.2" data-path="ComponentRegistry.html">
<a href="ComponentRegistry.html">
ComponentRegistry
</a>
</li>
<li class="chapter " data-level="2.5.3" data-path="ContactStore.html">
<a href="ContactStore.html">
ContactStore
</a>
</li>
<li class="chapter " data-level="2.5.4" data-path="FocusedContentStore.html">
<a href="FocusedContentStore.html">
FocusedContentStore
</a>
</li>
<li class="chapter " data-level="2.5.5" data-path="TaskQueue.html">
<a href="TaskQueue.html">
TaskQueue
</a>
</li>
<li class="chapter " data-level="2.5.6" data-path="WorkspaceStore.html">
<a href="WorkspaceStore.html">
WorkspaceStore
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.6" >
<span>
Database
</span>
<ul class="articles">
<li class="chapter " data-level="2.6.1" data-path="Attribute.html">
<a href="Attribute.html">
Attribute
</a>
</li>
<li class="chapter " data-level="2.6.2" data-path="AttributeBoolean.html">
<a href="AttributeBoolean.html">
AttributeBoolean
</a>
</li>
<li class="chapter " data-level="2.6.3" data-path="AttributeCollection.html">
<a href="AttributeCollection.html">
AttributeCollection
</a>
</li>
<li class="chapter " data-level="2.6.4" data-path="AttributeDateTime.html">
<a href="AttributeDateTime.html">
AttributeDateTime
</a>
</li>
<li class="chapter " data-level="2.6.5" data-path="AttributeJoinedData.html">
<a href="AttributeJoinedData.html">
AttributeJoinedData
</a>
</li>
<li class="chapter " data-level="2.6.6" data-path="AttributeNumber.html">
<a href="AttributeNumber.html">
AttributeNumber
</a>
</li>
<li class="chapter " data-level="2.6.7" data-path="AttributeObject.html">
<a href="AttributeObject.html">
AttributeObject
</a>
</li>
<li class="chapter " data-level="2.6.8" data-path="AttributeServerId.html">
<a href="AttributeServerId.html">
AttributeServerId
</a>
</li>
<li class="chapter " data-level="2.6.9" data-path="AttributeString.html">
<a href="AttributeString.html">
AttributeString
</a>
</li>
<li class="chapter " data-level="2.6.10" data-path="DatabaseStore.html">
<a href="DatabaseStore.html">
DatabaseStore
</a>
</li>
<li class="chapter " data-level="2.6.11" data-path="Matcher.html">
<a href="Matcher.html">
Matcher
</a>
</li>
<li class="chapter " data-level="2.6.12" data-path="ModelQuery.html">
<a href="ModelQuery.html">
ModelQuery
</a>
</li>
<li class="chapter " data-level="2.6.13" data-path="SortOrder.html">
<a href="SortOrder.html">
SortOrder
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.7" >
<span>
Drafts
</span>
<ul class="articles">
<li class="chapter " data-level="2.7.1" data-path="DraftChangeSet.html">
<a href="DraftChangeSet.html">
DraftChangeSet
</a>
</li>
<li class="chapter " data-level="2.7.2" data-path="DraftEditingSession.html">
<a href="DraftEditingSession.html">
DraftEditingSession
</a>
</li>
<li class="chapter " data-level="2.7.3" data-path="DraftStore.html">
<a href="DraftStore.html">
DraftStore
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.8" >
<span>
NylasEnv
</span>
<ul class="articles">
<li class="chapter " data-level="2.8.1" data-path="PackageManager.html">
<a href="PackageManager.html">
PackageManager
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.9" >
<span>
Atom
</span>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >Config</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="config"><a name="config" class="plugin-anchor" href="#config"><i class="fa fa-link" aria-hidden="true"></i></a>Config</h1>
<h2 id="summary"><a name="summary" class="plugin-anchor" href="#summary"><i class="fa fa-link" aria-hidden="true"></i></a>Summary</h2>
<p>Used to access all of N1&apos;s configuration details.</p>
<p>An instance of this class is always available as the <code>NylasEnv.config</code> global.</p>
<h2 id="getting-and-setting-config-settings"><a name="getting-and-setting-config-settings" class="plugin-anchor" href="#getting-and-setting-config-settings"><i class="fa fa-link" aria-hidden="true"></i></a>Getting and setting config settings.</h2>
<pre><code class="lang-coffee"><span class="hljs-comment"># Note that with no value set, ::get returns the setting&apos;s default value.</span>
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.myKey&apos;</span>) <span class="hljs-comment"># -&gt; &apos;defaultValue&apos;</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.myKey&apos;</span>, <span class="hljs-string">&apos;value&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.myKey&apos;</span>) <span class="hljs-comment"># -&gt; &apos;value&apos;</span>
</code></pre>
<p>You may want to watch for changes. Use <a href="#observe">observe</a> to catch changes to the setting.</p>
<pre><code class="lang-coffee">NylasEnv.config.set(<span class="hljs-string">&apos;my-package.myKey&apos;</span>, <span class="hljs-string">&apos;value&apos;</span>)
NylasEnv.config.observe <span class="hljs-string">&apos;my-package.myKey&apos;</span>, <span class="hljs-function"><span class="hljs-params">(newValue)</span> -&gt;</span>
<span class="hljs-comment"># `observe` calls immediately and every time the value is changed</span>
<span class="hljs-built_in">console</span>.log <span class="hljs-string">&apos;My configuration changed:&apos;</span>, newValue
</code></pre>
<p>If you want a notification only when the value changes, use <a href="#onDidChange">onDidChange</a>.</p>
<pre><code class="lang-coffee">NylasEnv.config.onDidChange <span class="hljs-string">&apos;my-package.myKey&apos;</span>, <span class="hljs-function"><span class="hljs-params">({newValue, oldValue})</span> -&gt;</span>
<span class="hljs-built_in">console</span>.log <span class="hljs-string">&apos;My configuration changed:&apos;</span>, newValue, oldValue
</code></pre>
<h3 id="value-coercion"><a name="value-coercion" class="plugin-anchor" href="#value-coercion"><i class="fa fa-link" aria-hidden="true"></i></a>Value Coercion</h3>
<p>Config settings each have a type specified by way of a
<a href="json-schema.org">schema</a>. For example we might an integer setting that only
allows integers greater than <code>0</code>:</p>
<pre><code class="lang-coffee"><span class="hljs-comment"># When no value has been set, `::get` returns the setting&apos;s default value</span>
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.anInt&apos;</span>) <span class="hljs-comment"># -&gt; 12</span>
<span class="hljs-comment"># The string will be coerced to the integer 123</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.anInt&apos;</span>, <span class="hljs-string">&apos;123&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.anInt&apos;</span>) <span class="hljs-comment"># -&gt; 123</span>
<span class="hljs-comment"># The string will be coerced to an integer, but it must be greater than 0, so is set to 1</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.anInt&apos;</span>, <span class="hljs-string">&apos;-20&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.anInt&apos;</span>) <span class="hljs-comment"># -&gt; 1</span>
</code></pre>
<h2 id="defining-settings-for-your-package"><a name="defining-settings-for-your-package" class="plugin-anchor" href="#defining-settings-for-your-package"><i class="fa fa-link" aria-hidden="true"></i></a>Defining settings for your package</h2>
<p>Define a schema under a <code>config</code> key in your package main.</p>
<pre><code class="lang-coffee"><span class="hljs-built_in">module</span>.exports =
<span class="hljs-comment"># Your config schema</span>
config:
someInt:
type: <span class="hljs-string">&apos;integer&apos;</span>
default: <span class="hljs-number">23</span>
minimum: <span class="hljs-number">1</span>
activate: <span class="hljs-function"><span class="hljs-params">(state)</span> -&gt;</span> <span class="hljs-comment"># ...</span>
<span class="hljs-comment"># ...</span>
</code></pre>
<h2 id="config-schemas"><a name="config-schemas" class="plugin-anchor" href="#config-schemas"><i class="fa fa-link" aria-hidden="true"></i></a>Config Schemas</h2>
<p>We use <a href="http://json-schema.org" target="_blank">json schema</a> which allows you to define your value&apos;s
default, the type it should be, etc. A simple example:</p>
<pre><code class="lang-coffee"><span class="hljs-comment"># We want to provide an `enableThing`, and a `thingVolume`</span>
config:
enableThing:
type: <span class="hljs-string">&apos;boolean&apos;</span>
default: <span class="hljs-literal">false</span>
thingVolume:
type: <span class="hljs-string">&apos;integer&apos;</span>
default: <span class="hljs-number">5</span>
minimum: <span class="hljs-number">1</span>
maximum: <span class="hljs-number">11</span>
</code></pre>
<p>The type keyword allows for type coercion and validation. If a <code>thingVolume</code> is
set to a string <code>&apos;10&apos;</code>, it will be coerced into an integer.</p>
<pre><code class="lang-coffee">NylasEnv.config.set(<span class="hljs-string">&apos;my-package.thingVolume&apos;</span>, <span class="hljs-string">&apos;10&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.thingVolume&apos;</span>) <span class="hljs-comment"># -&gt; 10</span>
<span class="hljs-comment"># It respects the min / max</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.thingVolume&apos;</span>, <span class="hljs-string">&apos;400&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.thingVolume&apos;</span>) <span class="hljs-comment"># -&gt; 11</span>
<span class="hljs-comment"># If it cannot be coerced, the value will not be set</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.thingVolume&apos;</span>, <span class="hljs-string">&apos;cats&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.thingVolume&apos;</span>) <span class="hljs-comment"># -&gt; 11</span>
</code></pre>
<h3 id="supported-types"><a name="supported-types" class="plugin-anchor" href="#supported-types"><i class="fa fa-link" aria-hidden="true"></i></a>Supported Types</h3>
<p>The <code>type</code> keyword can be a string with any one of the following. You can also
chain them by specifying multiple in an an array. For example</p>
<pre><code class="lang-coffee">config:
someSetting:
type: [<span class="hljs-string">&apos;boolean&apos;</span>, <span class="hljs-string">&apos;integer&apos;</span>]
default: <span class="hljs-number">5</span>
<span class="hljs-comment"># Then</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>, <span class="hljs-string">&apos;true&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>) <span class="hljs-comment"># -&gt; true</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>, <span class="hljs-string">&apos;12&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>) <span class="hljs-comment"># -&gt; 12</span>
</code></pre>
<h4 id="string"><a name="string" class="plugin-anchor" href="#string"><i class="fa fa-link" aria-hidden="true"></i></a>string</h4>
<p>Values must be a string.</p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;string&apos;</span>
default: <span class="hljs-string">&apos;hello&apos;</span>
</code></pre>
<h4 id="integer"><a name="integer" class="plugin-anchor" href="#integer"><i class="fa fa-link" aria-hidden="true"></i></a>integer</h4>
<p>Values will be coerced into integer. Supports the (optional) <code>minimum</code> and
<code>maximum</code> keys.</p>
<pre><code class="lang-coffee"> config:
someSetting:
type: <span class="hljs-string">&apos;integer&apos;</span>
default: <span class="hljs-number">5</span>
minimum: <span class="hljs-number">1</span>
maximum: <span class="hljs-number">11</span>
</code></pre>
<h4 id="number"><a name="number" class="plugin-anchor" href="#number"><i class="fa fa-link" aria-hidden="true"></i></a>number</h4>
<p>Values will be coerced into a number, including real numbers. Supports the
(optional) <code>minimum</code> and <code>maximum</code> keys.</p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;number&apos;</span>
default: <span class="hljs-number">5.3</span>
minimum: <span class="hljs-number">1.5</span>
maximum: <span class="hljs-number">11.5</span>
</code></pre>
<h4 id="boolean"><a name="boolean" class="plugin-anchor" href="#boolean"><i class="fa fa-link" aria-hidden="true"></i></a>boolean</h4>
<p>Values will be coerced into a Boolean. <code>&apos;true&apos;</code> and <code>&apos;false&apos;</code> will be coerced into
a boolean. Numbers, arrays, objects, and anything else will not be coerced.</p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;boolean&apos;</span>
default: <span class="hljs-literal">false</span>
</code></pre>
<h4 id="array"><a name="array" class="plugin-anchor" href="#array"><i class="fa fa-link" aria-hidden="true"></i></a>array</h4>
<p>Value must be an Array. The types of the values can be specified by a
subschema in the <code>items</code> key.</p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;array&apos;</span>
default: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
items:
type: <span class="hljs-string">&apos;integer&apos;</span>
minimum: <span class="hljs-number">1.5</span>
maximum: <span class="hljs-number">11.5</span>
</code></pre>
<h4 id="object"><a name="object" class="plugin-anchor" href="#object"><i class="fa fa-link" aria-hidden="true"></i></a>object</h4>
<p>Value must be an object. This allows you to nest config options. Sub options
must be under a <code>properties key</code></p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;object&apos;</span>
properties:
myChildIntOption:
type: <span class="hljs-string">&apos;integer&apos;</span>
minimum: <span class="hljs-number">1.5</span>
maximum: <span class="hljs-number">11.5</span>
</code></pre>
<h4 id="color"><a name="color" class="plugin-anchor" href="#color"><i class="fa fa-link" aria-hidden="true"></i></a>color</h4>
<p>Values will be coerced into a {Color} with <code>red</code>, <code>green</code>, <code>blue</code>, and <code>alpha</code>
properties that all have numeric values. <code>red</code>, <code>green</code>, <code>blue</code> will be in
the range 0 to 255 and <code>value</code> will be in the range 0 to 1. Values can be any
valid CSS color format such as <code>#abc</code>, <code>#abcdef</code>, <code>white</code>,
<code>rgb(50, 100, 150)</code>, and <code>rgba(25, 75, 125, .75)</code>.</p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;color&apos;</span>
default: <span class="hljs-string">&apos;white&apos;</span>
</code></pre>
<h3 id="other-supported-keys"><a name="other-supported-keys" class="plugin-anchor" href="#other-supported-keys"><i class="fa fa-link" aria-hidden="true"></i></a>Other Supported Keys</h3>
<h4 id="enum"><a name="enum" class="plugin-anchor" href="#enum"><i class="fa fa-link" aria-hidden="true"></i></a>enum</h4>
<p>All types support an <code>enum</code> key. The enum key lets you specify all values
that the config setting can possibly be. <code>enum</code> <em>must</em> be an array of values
of your specified type. Schema:</p>
<pre><code class="lang-coffee">config:
someSetting:
type: <span class="hljs-string">&apos;integer&apos;</span>
default: <span class="hljs-number">4</span>
enum: [<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>]
</code></pre>
<p>Usage:</p>
<pre><code class="lang-coffee">NylasEnv.config.set(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>, <span class="hljs-string">&apos;2&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>) <span class="hljs-comment"># -&gt; 2</span>
<span class="hljs-comment"># will not set values outside of the enum values</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>, <span class="hljs-string">&apos;3&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>) <span class="hljs-comment"># -&gt; 2</span>
<span class="hljs-comment"># If it cannot be coerced, the value will not be set</span>
NylasEnv.config.set(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>, <span class="hljs-string">&apos;4&apos;</span>)
NylasEnv.config.get(<span class="hljs-string">&apos;my-package.someSetting&apos;</span>) <span class="hljs-comment"># -&gt; 4</span>
</code></pre>
<h4 id="title-and-description"><a name="title-and-description" class="plugin-anchor" href="#title-and-description"><i class="fa fa-link" aria-hidden="true"></i></a>title and description</h4>
<p>The settings view will use the <code>title</code> and <code>description</code> keys to display your
config setting in a readable way. By default the settings view humanizes your
config key, so <code>someSetting</code> becomes <code>Some Setting</code>. In some cases, this is
confusing for users, and a more descriptive title is useful.</p>
<p>Descriptions will be displayed below the title in the settings view.</p>
<pre><code class="lang-coffee">config:
someSetting:
title: <span class="hljs-string">&apos;Setting Magnitude&apos;</span>
description: <span class="hljs-string">&apos;This will affect the blah and the other blah&apos;</span>
type: <span class="hljs-string">&apos;integer&apos;</span>
default: <span class="hljs-number">4</span>
</code></pre>
<p><strong>Note</strong>: You should strive to be so clear in your naming of the setting that
you do not need to specify a title or description!</p>
<h2 id="best-practices"><a name="best-practices" class="plugin-anchor" href="#best-practices"><i class="fa fa-link" aria-hidden="true"></i></a>Best practices</h2>
<ul>
<li>Don&apos;t depend on (or write to) configuration keys outside of your keypath.</li>
</ul>
<ul>
<li><a href="#Config%20Subscription">Config Subscription</a></li>
<li><a href="#Managing%20Settings">Managing Settings</a></li>
</ul>
<h3 id="instance-methods"><a name="instance-methods" class="plugin-anchor" href="#instance-methods"><i class="fa fa-link" aria-hidden="true"></i></a>Instance Methods</h3>
<h4 id="observe" class="function-name"><a name="observe" class="plugin-anchor" href="#observe"><i class="fa fa-link" aria-hidden="true"></i></a>
observe(<span class="args"><span class="arg">keyPath</span><span class="arg">callback</span></span>) <a href="#observe" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Add a listener for changes to a given key path. This is different
than <a href="#onDidChange">onDidChange</a> in that it will immediately call your callback with the
current value of the config entry.
### Examples
You might want to be notified when the themes change. We&apos;ll watch
`core.themes` for changes
```coffee
NylasEnv.config.observe &apos;core.themes&apos;, (value) -&gt;
# do stuff with value
```</p>
</div>
<p><strong>Parameters</strong></p>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>keyPath</em>
</td>
<td class="markdown-from-sourecode">
{String} name of the key to observe
</td>
</tr>
<tr>
<td style="width:15%;">
<em>callback</em>
</td>
<td class="markdown-from-sourecode">
{Function} to call when the value of the key changes.
</td>
</tr>
</table>
<p><strong>Returns</strong></p>
<table class="arguments">
<tr>
<th>Return Values</th>
</tr>
<tr><td class="markdown-from-sourecode">Returns a {Disposable} with the following keys on which you can call
`.dispose()` to unsubscribe.</td></tr>
</table>
<h4 id="onDidChange" class="function-name"><a name="onDidChange" class="plugin-anchor" href="#onDidChange"><i class="fa fa-link" aria-hidden="true"></i></a>
onDidChange(<span class="args"><span class="arg">[keyPath]</span><span class="arg">callback</span></span>) <a href="#onDidChange" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Add a listener for changes to a given key path. If `keyPath` is
not specified, your callback will be called on changes to any key.</p>
</div>
<strong>Parameters</strong>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>keyPath</em>
</td>
<td class="markdown-from-sourecode">
<span class="optional">Optional</span>
{String} name of the key to observe.
</td>
</tr>
<tr>
<td style="width:15%;">
<em>callback</em>
</td>
<td class="markdown-from-sourecode">
{Function} to call when the value of the key changes.
</td>
</tr>
</table>
<p><strong>Returns</strong></p>
<table class="arguments">
<tr>
<th>Return Values</th>
</tr>
<tr><td class="markdown-from-sourecode">Returns a {Disposable} with the following keys on which you can call
`.dispose()` to unsubscribe.</td></tr>
</table>
<h4 id="get" class="function-name"><a name="get" class="plugin-anchor" href="#get"><i class="fa fa-link" aria-hidden="true"></i></a>
get(<span class="args"><span class="arg">keyPath</span></span>) <a href="#get" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Retrieves the setting for the given key.
### Examples
You might want to know what themes are enabled, so check `core.themes`
```coffee
NylasEnv.config.get(&apos;core.themes&apos;)
```</p>
</div>
<strong>Parameters</strong>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>keyPath</em>
</td>
<td class="markdown-from-sourecode">
The {String} name of the key to retrieve.
</td>
</tr>
</table>
<p><strong>Returns</strong></p>
<table class="arguments">
<tr>
<th>Return Values</th>
</tr>
<tr><td class="markdown-from-sourecode">Returns the value from N1&apos;s default settings, the user&apos;s configuration
file in the type specified by the configuration schema.</td></tr>
</table>
<h4 id="set" class="function-name"><a name="set" class="plugin-anchor" href="#set"><i class="fa fa-link" aria-hidden="true"></i></a>
set(<span class="args"><span class="arg">keyPath</span><span class="arg">value</span></span>) <a href="#set" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Sets the value for a configuration setting.
This value is stored in N1&apos;s internal configuration file.
### Examples
You might want to change the themes programmatically:
```coffee
NylasEnv.config.set(&apos;core.themes&apos;, [&apos;ui-light&apos;, &apos;my-custom-theme&apos;])
```</p>
</div>
<strong>Parameters</strong>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>keyPath</em>
</td>
<td class="markdown-from-sourecode">
The {String} name of the key.
</td>
</tr>
<tr>
<td style="width:15%;">
<em>value</em>
</td>
<td class="markdown-from-sourecode">
The value of the setting. Passing `undefined` will revert the setting to the default value.
</td>
</tr>
</table>
<p><strong>Returns</strong></p>
<table class="arguments">
<tr>
<th>Return Values</th>
</tr>
<tr><td class="markdown-from-sourecode">Returns a {Boolean}
* `true` if the value was set.
* `false` if the value was not able to be coerced to the type specified in the setting&apos;s schema.</td></tr>
</table>
<h4 id="unset" class="function-name"><a name="unset" class="plugin-anchor" href="#unset"><i class="fa fa-link" aria-hidden="true"></i></a>
unset(<span class="args"><span class="arg">keyPath</span><span class="arg">[options]</span></span>) <a href="#unset" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Restore the setting at `keyPath` to its default value.</p>
</div>
<strong>Parameters</strong>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>keyPath</em>
</td>
<td class="markdown-from-sourecode">
The {String} name of the key.
</td>
</tr>
<tr>
<td style="width:15%;">
<em>options</em>
</td>
<td class="markdown-from-sourecode">
<span class="optional">Optional</span>
{Object}
</td>
</tr>
</table>
<h4 id="getSchema" class="function-name"><a name="getSchema" class="plugin-anchor" href="#getSchema"><i class="fa fa-link" aria-hidden="true"></i></a>
getSchema(<span class="args"><span class="arg">keyPath</span></span>) <a href="#getSchema" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Retrieve the schema for a specific key path. The schema will tell
you what type the keyPath expects, and other metadata about the config
option.</p>
</div>
<p><strong>Parameters</strong></p>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>keyPath</em>
</td>
<td class="markdown-from-sourecode">
The {String} name of the key.
</td>
</tr>
</table>
<p><strong>Returns</strong></p>
<table class="arguments">
<tr>
<th>Return Values</th>
</tr>
<tr><td class="markdown-from-sourecode">Returns an {Object} eg. `{type: &apos;integer&apos;, default: 23, minimum: 1}`.</td></tr>
<tr><td class="markdown-from-sourecode">Returns `null` when the keyPath has no schema specified.</td></tr>
</table>
<h4 id="transact" class="function-name"><a name="transact" class="plugin-anchor" href="#transact"><i class="fa fa-link" aria-hidden="true"></i></a>
transact(<span class="args"><span class="arg">callback</span></span>) <a href="#transact" class="link"></a>
</h4>
<div class="function-description markdown-from-sourecode">
<p>Suppress calls to handler functions registered with <a href="#onDidChange">onDidChange</a>
and <a href="#observe">observe</a> for the duration of `callback`. After `callback` executes,
handlers will be called once if the value for their key-path has changed.</p>
</div>
<strong>Parameters</strong>
<table class="arguments">
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td style="width:15%;">
<em>callback</em>
</td>
<td class="markdown-from-sourecode">
{Function} to execute while suppressing calls to handlers.
</td>
</tr>
</table>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="Color.html" class="navigation navigation-prev " aria-label="Previous page: Color">
<i class="fa fa-angle-left"></i>
</a>
<a href="Contenteditable.html" class="navigation navigation-next " aria-label="Next page: Contenteditable">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Config","level":"2.1.7","depth":2,"next":{"title":"Contenteditable","level":"2.1.8","depth":2,"path":"classes/Contenteditable.md","ref":"classes/Contenteditable.md","articles":[]},"previous":{"title":"Color","level":"2.1.6","depth":2,"path":"classes/Color.md","ref":"classes/Color.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search","lunr","-fontsettings","-sharing","anchors","github","editlink","favicon"],"root":"./docs_src","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"editlink":{"label":"Edit This Page","multilingual":false,"base":"https://github.com/nylas/nylas-mail-docs/tree/master"},"github":{"url":"https://github.com/nylas/nylas-mail-docs"},"favicon":{"shortcut":"/img/favicon.png"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"anchors":{},"highlight":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Nylas Mail Plugin SDK","links":{"sharing":{"facebook":false,"twitter":false}},"gitbook":"3.2.2"},"file":{"path":"classes/Config.md","mtime":"2017-01-30T10:28:19.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-30T10:28:53.038Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-editlink/plugin.js"></script>
</body>
</html>