mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-29 03:43:16 +08:00
497 lines
No EOL
70 KiB
JSON
497 lines
No EOL
70 KiB
JSON
{
|
|
"sections": [
|
|
{
|
|
"name": "Guides",
|
|
"description": "Get a tour of how we structured N1, and learn best practices for writing your own plugin.",
|
|
"items": [
|
|
{
|
|
"html": "<p>Packages lie at the heart of N1. Each part of the core experience is a separate package that uses the Nylas Package API to add functionality to the client. Want to make a read-only mail client? Remove the core <code>Composer</code> package and you'll see reply buttons and composer functionality disappear.</p>\n<p>Let's explore the files in a simple package that adds a Translate option to the Composer. When you tap the Translate button, we'll display a popup menu with a list of languages. When you pick a language, we'll make a web request and convert your reply into the desired language.</p>\n<h3 id=\"package-structure\">Package Structure</h3>\n<p>Each package is defined by a <code>package.json</code> file that includes its name, version and dependencies. Packages may also declare dependencies which are loaded from npm - in this case, the <a href=\"https://github.com/request/request\">request</a> library. You'll need to <code>npm install</code> these dependencies locally when developing the package.</p>\n<pre><code>{\n \"<span class=\"hljs-attribute\">name</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"translate\"</span></span>,\n \"<span class=\"hljs-attribute\">version</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"0.1.0\"</span></span>,\n \"<span class=\"hljs-attribute\">main</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"./lib/main\"</span></span>,\n \"<span class=\"hljs-attribute\">description</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"An example package for N1\"</span></span>,\n \"<span class=\"hljs-attribute\">license</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"Proprietary\"</span></span>,\n \"<span class=\"hljs-attribute\">engines</span>\": <span class=\"hljs-value\">{\n \"<span class=\"hljs-attribute\">atom</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"*\"</span>\n </span>}</span>,\n \"<span class=\"hljs-attribute\">dependencies</span>\": <span class=\"hljs-value\">{\n \"<span class=\"hljs-attribute\">request</span>\": <span class=\"hljs-value\"><span class=\"hljs-string\">\"^2.53\"</span>\n </span>}\n</span>}\n</code></pre><p>Our package also contains source files, a spec file with complete tests for the behavior the package adds, and a stylesheet for CSS:</p>\n<pre><code>-<span class=\"ruby\"> package.json\n</span>-<span class=\"ruby\"> lib/\n</span> -<span class=\"ruby\"> main.coffee\n</span> -<span class=\"ruby\"> translate-button.cjsx\n</span>-<span class=\"ruby\"> spec/\n</span> -<span class=\"ruby\"> main-spec.coffee\n</span>-<span class=\"ruby\"> stylesheets/\n</span> -<span class=\"ruby\"> translate.less</span>\n</code></pre><p><code>package.json</code> lists <code>lib/main</code> as the root file of our package. Since N1 runs NodeJS, we can <code>require</code> other source files, Node packages, etc.</p>\n<p>N1 can read <code>js</code>, <code>coffee</code>, <code>jsx</code>, and <code>cjsx</code> files automatically.</p>\n<p>Inside <code>main.coffee</code>, there are two important functions being exported:</p>\n<pre><code class=\"lang-coffee\"><span class=\"hljs-built_in\">require</span> <span class=\"hljs-string\">'./translate-button'</span>\n\n<span class=\"hljs-built_in\">module</span>.exports =\n\n <span class=\"hljs-comment\"># Activate is called when the package is loaded. If your package previously</span>\n <span class=\"hljs-comment\"># saved state using `serialize` it is provided.</span>\n <span class=\"hljs-comment\">#</span>\n <span class=\"hljs-attribute\">activate</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">(<span class=\"hljs-property\">@state</span>)</span> -></span>\n ComponentRegistry.register TranslateButton,\n <span class=\"hljs-attribute\">role</span>: <span class=\"hljs-string\">'Composer:ActionButton'</span>\n\n <span class=\"hljs-comment\"># Serialize is called when your package is about to be unmounted.</span>\n <span class=\"hljs-comment\"># You can return a state object that will be passed back to your package</span>\n <span class=\"hljs-comment\"># when it is re-activated.</span>\n <span class=\"hljs-comment\">#</span>\n <span class=\"hljs-attribute\">serialize</span>: <span class=\"hljs-function\">-></span>\n {}\n\n <span class=\"hljs-comment\"># This optional method is called when the window is shutting down,</span>\n <span class=\"hljs-comment\"># or when your package is being updated or disabled. If your package is</span>\n <span class=\"hljs-comment\"># watching any files, holding external resources, providing commands or</span>\n <span class=\"hljs-comment\"># subscribing to events, release them here.</span>\n <span class=\"hljs-comment\">#</span>\n <span class=\"hljs-attribute\">deactivate</span>: <span class=\"hljs-function\">-></span>\n ComponentRegistry.unregister(TranslateButton)\n</code></pre>\n<blockquote>\n<p>N1 uses CJSX, a CoffeeScript version of JSX, which makes it easy to express Virtual DOM in React <code>render</code> methods! You may want to add the <a href=\"https://github.com/babel/babel-sublime\">Babel</a> plugin to Sublime Text, or the <a href=\"https://atom.io/packages/language-cjsx\">CJSX Language</a> for syntax highlighting.</p>\n</blockquote>\n<h3 id=\"package-stylesheets\">Package Stylesheets</h3>\n<p>Style sheets for your package should be placed in the <em>styles</em> directory. Any style sheets in this directory will be loaded and attached to the DOM when your package is activated. Style sheets can be written as CSS or <a href=\"http://lesscss.org/\">Less</a>, but Less is recommended.</p>\n<p>Ideally, you won't need much in the way of styling. We've provided a standard set of components which define both the colors and UI elements for any package that fits into N1 seamlessly.</p>\n<p>If you <em>do</em> need special styling, try to keep only structural styles in the package stylesheets. If you <em>must</em> specify colors and sizing, these should be taken from the active theme's [ui-variables.less][ui-variables]. For more information, see the [theme variables docs][theme-variables]. If you follow this guideline, your package will look good out of the box with any theme!</p>\n<p>An optional <code>stylesheets</code> array in your <code>package.json</code> can list the style sheets by name to specify a loading order; otherwise, all style sheets are loaded.</p>\n<h3 id=\"package-assets\">Package Assets</h3>\n<p>Many packages need other static files, like images. You can add static files anywhere in your package directory, and reference them at runtime using the <code>nylas://</code> url scheme:</p>\n<pre><code><<span class=\"hljs-tag\">img</span> src=<span class=\"hljs-string\">\"nylas://my-package-name/assets/goofy.png\"</span>>\n\n<span class=\"hljs-tag\">a</span> = new <span class=\"hljs-function\"><span class=\"hljs-title\">Audio</span><span class=\"hljs-params\">()</span></span>\n<span class=\"hljs-tag\">a</span><span class=\"hljs-class\">.src</span> = <span class=\"hljs-string\">\"nylas://my-package-name/sounds/bloop.mp3\"</span>\n<span class=\"hljs-tag\">a</span>.<span class=\"hljs-function\"><span class=\"hljs-title\">play</span><span class=\"hljs-params\">()</span></span>\n</code></pre><h3 id=\"installing-a-package\">Installing a Package</h3>\n<p>N1 ships with many packages already bundled with the application. When the application launches, it looks for additional packages in <code>~/.nylas/dev/packages</code>. Each package you create belongs in its own directory inside this folder.</p>\n<p>In the future, it will be possible to install packages directly from within the client.</p>\n",
|
|
"meta": {
|
|
"Title": "Building a Package",
|
|
"Section": "Guides",
|
|
"Order": 1,
|
|
"title": "Building a Package",
|
|
"section": "Guides",
|
|
"order": 1
|
|
},
|
|
"name": "Building a Package",
|
|
"filename": "PackageOverview.md",
|
|
"link": "PackageOverview.html"
|
|
},
|
|
{
|
|
"html": "<p>The N1 user interface is conceptually organized into Sheets. Each Sheet represents a window of content. For example, the <code>Threads</code> sheet lies at the heart of the application. When the user chooses the "Files" tab, a separate <code>Files</code> sheet is displayed in place of <code>Threads</code>. When the user clicks a thread in single-pane mode, a <code>Thread</code> sheet is pushed on to the workspace and appears after a brief transition.</p>\n<p><img src=\"./images/sheets.png\"></p>\n<p>The {WorkspaceStore} maintains the state of the application's workspace and the stack of sheets currently being displayed. Your packages can declare "root" sheets which are listed in the app's main sidebar, or push custom sheets on top of sheets to display data.</p>\n<p>The Nylas Workspace supports two display modes: <code>split</code> and <code>list</code>. Each Sheet describes it's appearance in each of the view modes it supports. For example, the <code>Threads</code> sheet describes a three column <code>split</code> view and a single column <code>list</code> view. Other sheets, like <code>Files</code> register for only one mode, and the user's mode preference is ignored.</p>\n<p>For each mode, Sheets register a set of column names.</p>\n<p><img src=\"./images/columns.png\"></p>\n<pre><code class=\"lang-coffee\"><span class=\"hljs-variable\">@defineSheet</span> <span class=\"hljs-string\">'Threads'</span>, {<span class=\"hljs-attribute\">root</span>: true},\n <span class=\"hljs-attribute\">split</span>: [<span class=\"hljs-string\">'RootSidebar'</span>, <span class=\"hljs-string\">'ThreadList'</span>, <span class=\"hljs-string\">'MessageList'</span>, <span class=\"hljs-string\">'MessageListSidebar'</span>]\n <span class=\"hljs-attribute\">list</span>: [<span class=\"hljs-string\">'RootSidebar'</span>, <span class=\"hljs-string\">'ThreadList'</span>]\n</code></pre>\n<p>Column names are important. Once you've registered a sheet, your package (and other packages) register React components that appear in each column.</p>\n<p>Sheets also have a <code>Header</code> and <code>Footer</code> region that spans all of their content columns. You can register components to appear in these regions to display notifications, add bars beneath the toolbar, etc.</p>\n<pre><code class=\"lang-coffee\">ComponentRegistry<span class=\"hljs-class\">.register</span> AccountSidebar,\n location: WorkspaceStore<span class=\"hljs-class\">.Location</span><span class=\"hljs-class\">.RootSidebar</span>\n\n\nComponentRegistry<span class=\"hljs-class\">.register</span> NotificationsStickyBar,\n location: WorkspaceStore<span class=\"hljs-class\">.Sheet</span><span class=\"hljs-class\">.Threads</span><span class=\"hljs-class\">.Header</span>\n</code></pre>\n<p>Each column is laid out as a CSS Flexbox, making them extremely flexible. For more about layout using Flexbox, see Working with Flexbox.</p>\n<p>###Toolbars</p>\n<p>Toolbars in N1 are also powered by the {ComponentRegistry}. Though toolbars appear to be a single unit at the top of a sheet, they are divided into columns with the same widths as the columns in the sheet beneath them.</p>\n<p><img src=\"./images/toolbar.png\"></p>\n<p>Each Toolbar column is laid out using {Flexbox}. You can control where toolbar elements appear within the column using the CSS <code>order</code> attribute. To make it easy to position toolbar items on the left, right, or center of a column, we've added two "spacer" elements with <code>order:50</code> and <code>order:-50</code> that evenly use up available space. Other CSS attributes allow you to control whether your items shrink or expand as the column's size changes.</p>\n<p><img src=\"./images/toolbar-column.png\"></p>\n<p>To add items to a toolbar, you inject them via the {ComponentRegistry}. There are several ways of describing the location of a toolbar component which are useful in different scenarios:</p>\n<ul>\n<li><p><code><Location>.Toolbar</code>: This component will always appear in the toolbar above the column named <code><Location></code>.</p>\n<p> (Example: Compose button which appears above the Left Sidebar column, regardless of what else is there.)</p>\n</li>\n<li><p><code><ComponentName>.Toolbar</code>: This component will appear in the toolbar above <code><ComponentName></code>.</p>\n<p> (Example: Archive button that should always be coupled with the MessageList component, placed anywhere a MessageList component is placed.)</p>\n</li>\n<li><p><code>Global.Toolbar.Left</code>: This component will always be added to the leftmost column of the toolbar.</p>\n<p> (Example: Window Controls)</p>\n</li>\n</ul>\n",
|
|
"meta": {
|
|
"Title": "Interface Concepts",
|
|
"Section": "Guides",
|
|
"Order": 1,
|
|
"title": "Interface Concepts",
|
|
"section": "Guides",
|
|
"order": 1
|
|
},
|
|
"name": "Interface Concepts",
|
|
"filename": "InterfaceConcepts.md",
|
|
"link": "InterfaceConcepts.html"
|
|
},
|
|
{
|
|
"html": "<p>N1 uses <a href=\"https://facebook.github.io/react/\">React</a> to create a fast, responsive UI. Packages that want to extend the N1 interface should use React. Using React's <a href=\"https://facebook.github.io/react/jsx-in-depth.html\">JSX</a> syntax is optional, but both <a href=\"https://facebook.github.io/react/jsx-in-depth.html\">JSX</a> and <a href=\"https://github.com/jsdf/coffee-react\">CJSX</a> (CoffeeScript) are available.</p>\n<p>For a quick introduction to React, take a look at Facebook's <a href=\"https://facebook.github.io/react/getting-started.html\">Getting Started with React</a>.</p>\n<h4 id=\"react-components\">React Components</h4>\n<p>N1 provides a set of core React components you can use in your packages. Many of the standard components listen for key events, include considerations for different platforms, and have extensive CSS. Wrapping standard components makes it easy to build rich interfaces that are consistent with the rest of the N1 platform.</p>\n<p>To use a standard component, require it from <code>nylas-component-kit</code> and use it in your component's <code>render</code> method.</p>\n<p class=\"well\">Keep in mind that React's Component model is based on composition rather than inheritance. On other platforms, you might subclass {Popover} to create your own custom Popover. In React, you should wrap the standard Popover component in your own component, which provides the Popover with <code>props</code> and children to customize its behavior.</p>\n\n\n<p>Here's a quick look at standard components you can require from <code>nylas-component-kit</code>:</p>\n<ul>\n<li><p><strong>{Menu}</strong>: Allows you to display a list of items consistent with the rest of the N1 user experience.</p>\n</li>\n<li><p><strong>{Spinner}</strong>: Displays an indeterminate progress indicator centered within it's container.</p>\n</li>\n<li><p><strong>{Popover}</strong>: Component for creating menus and popovers that appear in response to a click and stay open until the user clicks outside them.</p>\n</li>\n<li><p><strong>{Flexbox}</strong>: Component for creating a Flexbox layout.</p>\n</li>\n<li><p><strong>{RetinaImg}</strong>: Replacement for standard <code><img></code> tags which automatically resolves the best version of the image for the user's display and can apply many image transforms.</p>\n</li>\n<li><p><strong>{ListTabular}</strong>: Component for creating a list of items backed by a paginating ModelView.</p>\n</li>\n<li><p><strong>{MultiselectList}</strong>: Component for creating a list that supports multi-selection. (Internally wraps ListTabular)</p>\n</li>\n<li><p><strong>{MultiselectActionBar}</strong>: Component for creating a contextual toolbar that is activated when the user makes a selection on a ModelView.</p>\n</li>\n<li><p><strong>{ResizableRegion}</strong>: Component that renders it's children inside a resizable region with a draggable handle.</p>\n</li>\n<li><p><strong>{TokenizingTextField}</strong>: Wraps a standard <code><input></code> and takes function props for tokenizing input values and displaying autocompletion suggestions.</p>\n</li>\n<li><p><strong>{EventedIFrame}</strong>: Replacement for the standard <code><iframe></code> tag which handles events directed at the iFrame to ensure a consistent user experience.</p>\n</li>\n</ul>\n<h2 id=\"react-component-injection\">React Component Injection</h2>\n<p>The N1 interface is composed at runtime from components added by different packages. The app's left sidebar contains components from the composer package, the source list package, the activity package, and more. You can leverage the flexiblity of this system to extend almost any part of N1's interface.</p>\n<h3 id=\"registering-components\">Registering Components</h3>\n<p>After you've created React components in your package, you should register them with the {ComponentRegistry}. The Component Registry manages the dynamic injection of components that makes N1 so extensible. You can request that your components appear in a specific <code>Location</code> defined by the {WorkspaceStore}, or register your component for a <code>Role</code> that another package has declared.</p>\n<blockquote>\n<p>The Component Registry allows you to insert your custom component without hacking up the DOM. Register for a <code>Location</code> or <code>Role</code> and your Component will be rendered into that part of the interface.</p>\n</blockquote>\n<p>It's easy to see where registered components are displayed in N1. Enable the Developer bar at the bottom of the app by opening the Inspector panel, and then click "<strong>Component Regions</strong>":</p>\n<p><img src=\"./images/injected-components.png\"></p>\n<p>Each region outlined in red is filled dynamically by looking up a React component or set of components from the Component Registry. You can see the role or location you'd need to register for, and the <code>props</code> that your component will receive in those locations.</p>\n<p>Here are a few examples of how to use it to extend N1. Typically, packages register components in their main <code>activate</code> method, and unregister them in <code>deactivate</code>:</p>\n<ol>\n<li><p>Add a component to the Thread List column:</p>\n<pre><code class=\"lang-coffee\"> ComponentRegistry<span class=\"hljs-class\">.register</span> ThreadList,\n location: WorkspaceStore<span class=\"hljs-class\">.Location</span><span class=\"hljs-class\">.ThreadList</span>\n</code></pre>\n</li>\n<li><p>Add a component to the action bar at the bottom of the Composer:</p>\n<pre><code class=\"lang-coffee\"> <span class=\"hljs-tag\">ComponentRegistry</span><span class=\"hljs-class\">.register</span> <span class=\"hljs-tag\">TemplatePicker</span>,\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">role</span>:<span class=\"hljs-value\"> <span class=\"hljs-string\">'Composer:ActionButton'</span></span></span>\n</code></pre>\n</li>\n<li><p>Replace the <code>Participants</code> component that ships with N1 to display thread participants on your own:</p>\n<pre><code class=\"lang-coffee\"> <span class=\"hljs-tag\">ComponentRegistry</span><span class=\"hljs-class\">.register</span> <span class=\"hljs-tag\">ParticipantsWithStatusDots</span>,\n <span class=\"hljs-rule\"><span class=\"hljs-attribute\">role</span>:<span class=\"hljs-value\"> <span class=\"hljs-string\">'Participants'</span></span></span>\n</code></pre>\n</li>\n</ol>\n<p><em>Tip: Remember to unregister components in the <code>deactivate</code> method of your package.</em></p>\n<h3 id=\"using-registered-components\">Using Registered Components</h3>\n<p>It's easy to build packages that use the Component Registry to display components vended by other parts of the application. You can query the Component Registry and display the components it returns. The Component Registry is a Reflux-compatible Store, so you can listen to it and update your state as the registry changes.</p>\n<p>There are also several convenience components that make it easy to dynamically inject components into your Virtual DOM. These are the preferred way of using injected components.</p>\n<ul>\n<li>{InjectedComponent}: Renders the first component for the <code>matching</code> criteria you provide, and passes it the props in <code>externalProps</code>. See the API reference for more information.</li>\n</ul>\n<pre><code class=\"lang-coffee\"><InjectedComponent\n matching={<span class=\"hljs-string\">role:</span><span class=\"hljs-string\">\"Attachment\"</span>}\n exposedProps={<span class=\"hljs-string\">file:</span> file, <span class=\"hljs-string\">messageLocalId:</span> <span class=\"hljs-annotation\">@props</span>.localId}/>\n</code></pre>\n<ul>\n<li>{InjectedComponentSet}: Renders all of the components <code>matching</code> criteria you provide inside a {Flexbox}, and passes it the props in <code>externalProps</code>. See the API reference for more information.</li>\n</ul>\n<pre><code class=\"lang-coffee\"><InjectedComponentSet\n className=<span class=\"hljs-string\">\"message-actions\"</span>\n matching={<span class=\"hljs-string\">role:</span><span class=\"hljs-string\">\"MessageAction\"</span>}\n exposedProps={<span class=\"hljs-string\">thread:</span><span class=\"hljs-annotation\">@props</span>.thread, <span class=\"hljs-string\">message:</span> <span class=\"hljs-annotation\">@props</span>.message}>\n</code></pre>\n<h3 id=\"unsafe-components\">Unsafe Components</h3>\n<p>N1 considers all injected components "unsafe". When you render them using {InjectedComponent} or {InjectedComponentSet}, they will be wrapped in a component that prevents exceptions in their React render and lifecycle methods from impacting your component. Instead of your component triggering a React Invariant exception in the application, an exception notice will be rendered in place of the unsafe component.</p>\n<p><img src=\"./images/unsafe-component-exception.png\"></p>\n<p>In the future, N1 may automatically disable packages when their React components throw exceptions.</p>\n",
|
|
"meta": {
|
|
"Title": "Interface Components",
|
|
"Section": "Guides",
|
|
"Order": 2,
|
|
"title": "Interface Components",
|
|
"section": "Guides",
|
|
"order": 2
|
|
},
|
|
"name": "Interface Components",
|
|
"filename": "React.md",
|
|
"link": "React.html"
|
|
},
|
|
{
|
|
"html": "<p>N1 uses <a href=\"https://github.com/spoike/refluxjs\">Reflux</a>, a slim implementation of Facebook's <a href=\"https://facebook.github.io/flux/\">Flux Application Architecture</a> to coordinate the movement of data through the application. Flux is extremely well suited for applications that support third-party extension because it emphasizes loose coupling and well defined interfaces between components. It enforces:</p>\n<ul>\n<li><strong>Uni-directional data flow</strong></li>\n<li><strong>Loose coupling between components</strong></li>\n</ul>\n<p>For more information about the Flux pattern, check out <a href=\"https://facebook.github.io/flux/docs/overview.html#structure-and-data-flow\">this diagram</a>. For a bit more insight into why we chose Reflux over other Flux implementations, there's a great <a href=\"http://spoike.ghost.io/deconstructing-reactjss-flux/\">blog post</a> by the author of Reflux.</p>\n<p>There are several core stores in the application:</p>\n<ul>\n<li><p><strong>{AccountStore}</strong>: When the user signs in to N1, their auth token provides one or more accounts. The AccountStore manages the available Accounts, exposes the current Account, and allows you to observe changes to the current Account.</p>\n</li>\n<li><p><strong>{TaskQueue}</strong>: Manages Tasks, operations queued for processing on the backend. Task objects represent individual API actions and are persisted to disk, ensuring that they are performed eventually. Each Task may depend on other tasks, and Tasks are executed in order.</p>\n</li>\n<li><p><strong>{DatabaseStore}</strong>: The {DatabaseStore} marshalls data in and out of the local cache, and exposes an ActiveRecord-style query interface. You can observe the DatabaseStore to monitor the state of data in N1.</p>\n</li>\n<li><p><strong>{DraftStore}</strong>: Manages Drafts, which are {Message} objects the user is authoring. Drafts present a unique case in N1 because they may be updated frequently by disconnected parts of the application. You should use the {DraftStore} to create, edit, and send drafts.</p>\n</li>\n<li><p><strong>{FocusedContentStore}</strong>: Manages focus within the main applciation window. The {FocusedContentStore} allows you to query and monitor changes to the selected thread, tag, file, etc.</p>\n</li>\n</ul>\n<p>Most packages declare additional stores that subscribe to these Stores, as well as user Actions, and vend data to the package's React components.</p>\n<h3 id=\"actions\">Actions</h3>\n<p>In Flux applications, views fire {Actions}, which anyone in the application can subscribe to. Typically, <code>Stores</code> listen to actions to perform business logic and trigger updates to their corresponding views. For example, when you click "Compose" in the top left corner of N1, the React component for the button fires {Actions::composeNewBlankDraft}. The {DraftStore} listens to this action and opens a new composer window.</p>\n<p>This approach means that your packages can fire existing {Actions}, like {Actions::composeNewBlankDraft}, or observe actions to add functionality. (For example, we have an Analytics package that also listens for {Actions::composeNewBlankDraft} and counts how many times it's been fired.) You can also define your own actions for use within your package.</p>\n<p>For a complete list of available actions, see {Actions}.</p>\n",
|
|
"meta": {
|
|
"Title": "Application Architecture",
|
|
"Section": "Guides",
|
|
"Order": 3,
|
|
"title": "Application Architecture",
|
|
"section": "Guides",
|
|
"order": 3
|
|
},
|
|
"name": "Application Architecture",
|
|
"filename": "Architecture.md",
|
|
"link": "Architecture.html"
|
|
},
|
|
{
|
|
"html": "<h3 id=\"chromium-devtools\">Chromium DevTools</h3>\n<p>N1 is built on top of Electron, which runs the latest version of Chromium (at the time of writing, Chromium 43). You can access the standard <a href=\"https://developer.chrome.com/devtools\">Chrome DevTools</a> using the <code>Command-Option-I</code> (<code>Ctrl-Shift-I</code> on Windows/Linux) keyboard shortcut, including the Debugger, Profiler, and Console. You can find extensive information about the Chromium DevTools on <a href=\"https://developer.chrome.com/devtools\">developer.chrome.com</a>.</p>\n<p>Here are a few hidden tricks for getting the most out of the Chromium DevTools:</p>\n<ul>\n<li><p>You can use <code>Command-P</code> to "Open Quickly", jumping to a particular source file from any tab.</p>\n</li>\n<li><p>You can set breakpoints by clicking the line number gutter while viewing a source file.</p>\n</li>\n<li><p>While on a breakpoint, you can toggle the console panel by pressing <code>Esc</code> and type commands which are executed in the current scope.</p>\n</li>\n<li><p>While viewing the DOM in the <code>Elements</code> panel, typing <code>$0</code> on the console refers to the currently selected DOM node.</p>\n</li>\n</ul>\n<h3 id=\"nylas-developer-panel\">Nylas Developer Panel</h3>\n<p>If you choose <code>Developer > Relaunch with Debug Flags...</code> from the menu, you can enable the Nylas Developer Panel at the bottom of the main window.</p>\n<p>The Developer Panel provides three views which you can click to activate:</p>\n<ul>\n<li><p><code>Tasks</code>: This view allows you to inspect the {TaskQueue} and see the what tasks are pending and complete. Click a task to see its JSON representation and inspect it's values, including the last error it encountered.</p>\n</li>\n<li><p><code>Delta Stream</code>: This view allows you to see the streaming updates from the Nylas API that the app has received. You can click individual updates to see the exact JSON that was consumed by the app, and search in the lower left for updates pertaining to an object ID or type.</p>\n</li>\n<li><p><code>Requests</code>: This view shows the requests the app has made to the Nylas API in <code>curl</code>-equivalent form. (The app does not actually make <code>curl</code> requests). You can click "Copy" to copy a <code>curl</code> command to the clipboard, or "Run" to execute it in a new Terminal window.</p>\n</li>\n</ul>\n<p>The Developer Panel also allows you to toggle "View Component Regions". Turning on component regions adds a red border to areas of the app that render dynamically injected components, and shows the props passed to React components in each one. See {react} for more information.</p>\n<h3 id=\"the-development-workflow\">The Development Workflow</h3>\n<p>If you're debugging a package, you'll be modifying your code and re-running N1 over and over again. There are a few things you can do to make this development workflow less time consuming:</p>\n<ul>\n<li><p><strong>Inline Changes</strong>: Using the Chromium DevTools, you can change the contents of your coffeescript and javascript source files, type <code>Command-S</code> to save, and hot-swap the code. This makes it easy to test small adjustments to your code without re-launching N1.</p>\n</li>\n<li><p><strong>View > Refresh</strong>: From the View menu, choose "Refresh" to reload the N1 window just like a page in your browser. Refreshing is faster than restarting the app and allows you to iterate more quickly.</p>\n<blockquote>\n<p>Note: A bug in Electron causes the Chromium DevTools to become detatched if you refresh the app often. If you find that Chromium is not stopping at your breakpoints, quit N1 and re-launch it.</p>\n</blockquote>\n</li>\n</ul>\n<p>In the future, we'll support much richer hot-reloading of plugin components and code. Stay tuned!</p>\n",
|
|
"meta": {
|
|
"Title": "Debugging N1",
|
|
"Section": "Guides",
|
|
"Order": 4,
|
|
"title": "Debugging N1",
|
|
"section": "Guides",
|
|
"order": 4
|
|
},
|
|
"name": "Debugging N1",
|
|
"filename": "Debugging.md",
|
|
"link": "Debugging.html"
|
|
},
|
|
{
|
|
"html": "<p>N1 is built on top of a custom database layer modeled after ActiveRecord. For many parts of the application, the database is the source of truth. Data is retrieved from the API, written to the database, and changes to the database trigger Stores and components to refresh their contents. The illustration below shows this flow of data:</p>\n<p><img src=\"./images/database-flow.png\"></p>\n<p>The Database connection is managed by the {DatabaseStore}, a singleton object that exists in every window. All Database requests are asynchronous. Queries are forwarded to the application's <code>Browser</code> process via IPC and run in SQLite.</p>\n<h2 id=\"declaring-models\">Declaring Models</h2>\n<p>In N1, Models are thin wrappers around data with a particular schema. Each {Model} class declares a set of attributes that define the object's data. For example:</p>\n<pre><code class=\"lang-coffee\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">Example</span> <span class=\"hljs-keyword\"><span class=\"hljs-keyword\">extends</span></span> <span class=\"hljs-title\">Model</span>\n</span>\n <span class=\"hljs-annotation\">@attributes</span>:\n <span class=\"hljs-symbol\">'i</span>d': <span class=\"hljs-type\">Attributes</span>.<span class=\"hljs-type\">String</span>\n queryable: <span class=\"hljs-literal\">true</span>\n modelKey: <span class=\"hljs-symbol\">'i</span>d'\n\n <span class=\"hljs-symbol\">'objec</span>t': <span class=\"hljs-type\">Attributes</span>.<span class=\"hljs-type\">String</span>\n modelKey: <span class=\"hljs-symbol\">'objec</span>t'\n\n <span class=\"hljs-symbol\">'namespaceI</span>d': <span class=\"hljs-type\">Attributes</span>.<span class=\"hljs-type\">String</span>\n queryable: <span class=\"hljs-literal\">true</span>\n modelKey: <span class=\"hljs-symbol\">'namespaceI</span>d'\n jsonKey: <span class=\"hljs-symbol\">'namespace_i</span>d'\n\n <span class=\"hljs-symbol\">'bod</span>y': <span class=\"hljs-type\">Attributes</span>.<span class=\"hljs-type\">JoinedData</span>\n modelTable: <span class=\"hljs-symbol\">'MessageBod</span>y'\n modelKey: <span class=\"hljs-symbol\">'bod</span>y'\n\n <span class=\"hljs-symbol\">'file</span>s': <span class=\"hljs-type\">Attributes</span>.<span class=\"hljs-type\">Collection</span>\n modelKey: <span class=\"hljs-symbol\">'file</span>s'\n itemClass: <span class=\"hljs-type\">File</span>\n\n <span class=\"hljs-symbol\">'unrea</span>d': <span class=\"hljs-type\">Attributes</span>.<span class=\"hljs-type\">Boolean</span>\n queryable: <span class=\"hljs-literal\">true</span>\n modelKey: <span class=\"hljs-symbol\">'unrea</span>d'\n</code></pre>\n<p>When models are inflated from JSON using <code>fromJSON</code> or converted to JSON using <code>toJSON</code>, only the attributes declared on the model are copied. The <code>modelKey</code> and <code>jsonKey</code> options allow you to specify where a particular key should be found. Attributes are also coerced to the proper types: String attributes will always be strings, Boolean attributes will always be <code>true</code> or <code>false</code>, etc. <code>null</code> is a valid value for all types.</p>\n<p>The {DatabaseStore} automatically maintains cache tables for storing Model objects. By default, models are stored in the cache as JSON blobs and basic attributes are not queryable. When the <code>queryable</code> option is specified on an attribute, it is given a separate column and index in the SQLite table for the model, and you can construct queries using the attribute:</p>\n<pre><code class=\"lang-coffee\">Thread<span class=\"hljs-class\">.attributes</span><span class=\"hljs-class\">.namespaceId</span><span class=\"hljs-class\">.equals</span>(<span class=\"hljs-string\">\"123\"</span>)\n<span class=\"hljs-comment\">// where namespace_id = '123'</span>\n\nThread<span class=\"hljs-class\">.attributes</span><span class=\"hljs-class\">.lastMessageTimestamp</span><span class=\"hljs-class\">.greaterThan</span>(<span class=\"hljs-number\">123</span>)\n<span class=\"hljs-comment\">// where last_message_timestamp > 123</span>\n\nThread<span class=\"hljs-class\">.attributes</span><span class=\"hljs-class\">.lastMessageTimestamp</span><span class=\"hljs-class\">.descending</span>()\n<span class=\"hljs-comment\">// order by last_message_timestamp DESC</span>\n</code></pre>\n<h2 id=\"retrieving-models\">Retrieving Models</h2>\n<p>You can make queries for models stored in SQLite using a {Promise}-based ActiveRecord-style syntax. There is no way to make raw SQL queries against the local data store.</p>\n<pre><code class=\"lang-coffee\">DatabaseStore.find<span class=\"hljs-function\"><span class=\"hljs-params\">(Thread, <span class=\"hljs-string\">'123'</span>)</span>.<span class=\"hljs-title\">then</span> <span class=\"hljs-params\">(thread)</span> -></span>\n <span class=\"hljs-comment\"># thread is a thread object</span>\n\nDatabaseStore.findBy<span class=\"hljs-function\"><span class=\"hljs-params\">(Thread, {subject: <span class=\"hljs-string\">'Hello World'</span>})</span>.<span class=\"hljs-title\">then</span> <span class=\"hljs-params\">(thread)</span> -></span>\n <span class=\"hljs-comment\"># find a single thread by subject</span>\n\nDatabaseStore.findAll<span class=\"hljs-function\"><span class=\"hljs-params\">(Thread)</span>.<span class=\"hljs-title\">where</span><span class=\"hljs-params\">([Thread.attributes.tags.contains(<span class=\"hljs-string\">'inbox'</span>)])</span>.<span class=\"hljs-title\">then</span> <span class=\"hljs-params\">(threads)</span> -></span>\n <span class=\"hljs-comment\"># find threads with the inbox tag</span>\n\nDatabaseStore.count<span class=\"hljs-function\"><span class=\"hljs-params\">(Thread)</span>.<span class=\"hljs-title\">where</span><span class=\"hljs-params\">([Thread.attributes.lastMessageTimestamp.greaterThan(<span class=\"hljs-number\">120315123</span>)])</span>.<span class=\"hljs-title\">then</span> <span class=\"hljs-params\">(results)</span> -></span>\n <span class=\"hljs-comment\"># count threads where last message received since 120315123.</span>\n</code></pre>\n<h2 id=\"retrieving-pages-of-models\">Retrieving Pages of Models</h2>\n<p>If you need to paginate through a view of data, you should use a <code>DatabaseView</code>. Database views can be configured with a sort order and a set of where clauses. After the view is configured, it maintains a cache of models in memory in a highly efficient manner and makes it easy to implement pagination. <code>DatabaseView</code> also performs deep inspection of it's cache when models are changed and can avoid costly SQL queries.</p>\n<h2 id=\"saving-and-updating-models\">Saving and Updating Models</h2>\n<p>The {DatabaseStore} exposes two methods for creating and updating models: <code>persistModel</code> and <code>persistModels</code>. When you call <code>persistModel</code>, queries are automatically executed to update the object in the cache and the {DatabaseStore} triggers, broadcasting an update to the rest of the application so that views dependent on these kind of models can refresh.</p>\n<p>When possible, you should accumulate the objects you want to save and call <code>persistModels</code>. The {DatabaseStore} will generate batch insert statements, and a single notification will be broadcast throughout the application. Since saving objects can result in objects being re-fetched by many stores and components, you should be mindful of database insertions.</p>\n<h2 id=\"saving-drafts\">Saving Drafts</h2>\n<p>Drafts in N1 presented us with a unique challenge. The same draft may be edited rapidly by unrelated parts of the application, causing race scenarios. (For example, when the user is typing and attachments finish uploading at the same time.) This problem could be solved by object locking, but we chose to marshall draft changes through a central DraftStore that debounces database queries and adds other helpful features. See the {DraftStore} documentation for more information.</p>\n<h2 id=\"removing-models\">Removing Models</h2>\n<p>The {DatabaseStore} exposes a single method, <code>unpersistModel</code>, that allows you to purge an object from the cache. You cannot remove a model by ID alone - you must load it first.</p>\n<h4 id=\"advanced-model-attributes\">Advanced Model Attributes</h4>\n<h5 id=\"attribute-joineddata\">Attribute.JoinedData</h5>\n<p>Joined Data attributes allow you to store certain attributes of an object in a separate table in the database. We use this attribute type for Message bodies. Storing message bodies, which can be very large, in a separate table allows us to make queries on message metadata extremely fast, and inflate Message objects without their bodies to build the thread list.</p>\n<p>When building a {ModelQuery} on a model with a {JoinedDataAttribute}, you need to call <code>include</code> to explicitly load the joined data attribute. The query builder will automatically perform a <code>LEFT OUTER JOIN</code> with the secondary table to retrieve the attribute:</p>\n<pre><code class=\"lang-coffee\">DatabaseStore.<span class=\"hljs-function\"><span class=\"hljs-title\">find</span><span class=\"hljs-params\">(Message, <span class=\"hljs-string\">'123'</span>)</span></span><span class=\"hljs-class\">.then</span> (message) ->\n <span class=\"hljs-comment\">// message.body is undefined</span>\n\nDatabaseStore.<span class=\"hljs-function\"><span class=\"hljs-title\">find</span><span class=\"hljs-params\">(Message, <span class=\"hljs-string\">'123'</span>)</span></span>.<span class=\"hljs-function\"><span class=\"hljs-title\">include</span><span class=\"hljs-params\">(Message.attributes.body)</span></span><span class=\"hljs-class\">.then</span> (message) ->\n <span class=\"hljs-comment\">// message.body is defined</span>\n</code></pre>\n<p>When you call <code>persistModel</code>, JoinedData attributes are automatically written to the secondary table.</p>\n<p>JoinedData attributes cannot be <code>queryable</code>.</p>\n<h5 id=\"attribute-collection\">Attribute.Collection</h5>\n<p>Collection attributes provide basic support for one-to-many relationships. For example, {Thread}s in N1 have a collection of {Tag}s.</p>\n<p>When Collection attributes are marked as <code>queryable</code>, the {DatabaseStore} automatically creates a join table and maintains it as you create, save, and delete models. When you call <code>persistModel</code>, entries are added to the join table associating the ID of the model with the IDs of models in the collection.</p>\n<p>Collection attributes have an additional clause builder, <code>contains</code>:</p>\n<pre><code class=\"lang-coffee\">DatabaseStore.<span class=\"hljs-function\"><span class=\"hljs-title\">findAll</span><span class=\"hljs-params\">(Thread)</span></span>.<span class=\"hljs-function\"><span class=\"hljs-title\">where</span><span class=\"hljs-params\">([Thread.attributes.tags.contains(<span class=\"hljs-string\">'inbox'</span>)</span></span>])\n</code></pre>\n<p>This is equivalent to writing the following SQL:</p>\n<pre><code class=\"lang-sql\">SELECT <span class=\"hljs-escape\">`T</span>hread<span class=\"hljs-escape\">`.</span><span class=\"hljs-escape\">`d</span>ata<span class=\"hljs-escape\">` </span>FROM <span class=\"hljs-escape\">`T</span>hread<span class=\"hljs-escape\">` </span>INNER JOIN <span class=\"hljs-escape\">`T</span>hread-Tag<span class=\"hljs-escape\">` </span>AS <span class=\"hljs-escape\">`M</span>1<span class=\"hljs-escape\">` </span>ON <span class=\"hljs-escape\">`M</span>1<span class=\"hljs-escape\">`.</span><span class=\"hljs-escape\">`i</span>d<span class=\"hljs-escape\">` </span>= <span class=\"hljs-escape\">`T</span>hread<span class=\"hljs-escape\">`.</span><span class=\"hljs-escape\">`i</span>d<span class=\"hljs-escape\">` </span>WHERE <span class=\"hljs-escape\">`M</span>1<span class=\"hljs-escape\">`.</span><span class=\"hljs-escape\">`v</span>alue<span class=\"hljs-escape\">` </span>= 'inbox' ORDER BY <span class=\"hljs-escape\">`T</span>hread<span class=\"hljs-escape\">`.</span><span class=\"hljs-escape\">`l</span>ast_message_timestamp<span class=\"hljs-escape\">` </span>DESC\n</code></pre>\n<h4 id=\"listening-for-changes\">Listening for Changes</h4>\n<p>For many parts of the application, the Database is the source of truth. Funneling changes through the database ensures that they are available to the entire application. Basing your packages on the Database, and listening to it for changes, ensures that your views never fall out of sync.</p>\n<p>Within Reflux Stores, you can listen to the {DatabaseStore} using the <code>listenTo</code> helper method:</p>\n<pre><code class=\"lang-coffee\"><span class=\"hljs-variable\">@listenTo</span>(DatabaseStore, <span class=\"hljs-variable\">@_onDataChanged</span>)\n</code></pre>\n<p>Within generic code, you can listen to the {DatabaseStore} using this syntax:</p>\n<pre><code class=\"lang-coffee\"><span class=\"hljs-variable\">@unlisten</span> = DatabaseStore.<span class=\"hljs-function\">listen</span>(<span class=\"hljs-variable\">@_onDataChanged</span>, @)\n</code></pre>\n<p>When a model is persisted or unpersisted from the database, your listener method will fire. It's very important to inspect the change payload before making queries to refresh your data. The change payload is a simple object with the following keys:</p>\n<pre><code>{\n <span class=\"hljs-string\">\"objectClass\"</span>: <span class=\"hljs-comment\">// string: the name of the class that was changed. ie: \"Thread\"</span>\n <span class=\"hljs-string\">\"objects\"</span>: <span class=\"hljs-comment\">// array: the objects that were persisted or removed</span>\n}\n</code></pre><h2 id=\"but-why-can-t-i-\">But why can't I...?</h2>\n<p>N1 exposes a minimal Database API that exposes high-level methods for saving and retrieving objects. The API was designed with several goals in mind, which will help us create a healthy ecosystem of third-party packages:</p>\n<ul>\n<li><p>Package code should not be tightly coupled to SQLite</p>\n</li>\n<li><p>Queries should be composed in a way that makes invalid queries impossible</p>\n</li>\n<li><p>All changes to the local database must be observable</p>\n</li>\n</ul>\n",
|
|
"meta": {
|
|
"Title": "Accessing the Database",
|
|
"Section": "Guides",
|
|
"Order": 5,
|
|
"title": "Accessing the Database",
|
|
"section": "Guides",
|
|
"order": 5
|
|
},
|
|
"name": "Accessing the Database",
|
|
"filename": "Database.md",
|
|
"link": "Database.html"
|
|
},
|
|
{
|
|
"html": "<p>The composer lies at the heart of N1, and many improvements to the mail experience require deep integration with the composer. To enable these sort of plugins, the {DraftStore} exposes an extension API.</p>\n<p>This API allows your package to:</p>\n<ul>\n<li><p>Display warning messages before a draft is sent. (ie: "Are you sure you want to send this without attaching a file?")</p>\n</li>\n<li><p>Intercept keyboard and mouse events to the composer's text editor.</p>\n</li>\n<li><p>Transform the draft and make additional changes before it is sent.</p>\n</li>\n</ul>\n<p>To create your own composer extensions, subclass {DraftStoreExtension} and override the methods your extension needs.</p>\n<p>In the sample packages repository, <a href=\"\">templates</a> is an example of a package which uses a DraftStoreExtension to enhance the composer experience.</p>\n<h3 id=\"example\">Example</h3>\n<p>This extension displays a warning before sending a draft that contains the names of competitors' products. If the user proceeds to send the draft containing the words, it appends a disclaimer.</p>\n<pre><code class=\"lang-coffee\">{DraftStoreExtension} = <span class=\"hljs-built_in\">require</span> <span class=\"hljs-string\">'nylas-exports'</span>\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class</span> <span class=\"hljs-title\">ProductsExtension</span> <span class=\"hljs-keyword\">extends</span> <span class=\"hljs-title\">DraftStoreExtension</span></span>\n\n <span class=\"hljs-property\">@warningsForSending</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">(draft)</span> -></span>\n words = [<span class=\"hljs-string\">'acme'</span>, <span class=\"hljs-string\">'anvil'</span>, <span class=\"hljs-string\">'tunnel'</span>, <span class=\"hljs-string\">'rocket'</span>, <span class=\"hljs-string\">'dynamite'</span>]\n body = draft.body.toLowercase()\n <span class=\"hljs-keyword\">for</span> word <span class=\"hljs-keyword\">in</span> words\n <span class=\"hljs-keyword\">if</span> body.indexOf(word) > <span class=\"hljs-number\">0</span>\n <span class=\"hljs-keyword\">return</span> [<span class=\"hljs-string\">\"with the word '<span class=\"hljs-subst\">#{word}</span>'?\"</span>]\n <span class=\"hljs-keyword\">return</span> []\n\n <span class=\"hljs-property\">@finalizeSessionBeforeSending</span>: <span class=\"hljs-function\"><span class=\"hljs-params\">(session)</span> -></span>\n draft = session.draft()\n <span class=\"hljs-keyword\">if</span> <span class=\"hljs-property\">@warningsForSending</span>(draft)\n bodyWithWarning = draft.body += <span class=\"hljs-string\">\"<br>This email \\\n contains competitor's product names \\\n or trademarks used in context.\"</span>\n session.changes.add(<span class=\"hljs-attribute\">body</span>: bodyWithWarning)\n</code></pre>\n",
|
|
"meta": {
|
|
"Title": "Extending the Composer",
|
|
"Section": "Guides",
|
|
"Order": 6,
|
|
"title": "Extending the Composer",
|
|
"section": "Guides",
|
|
"order": 6
|
|
},
|
|
"name": "Extending the Composer",
|
|
"filename": "DraftStoreExtensions.md",
|
|
"link": "DraftStoreExtensions.html"
|
|
},
|
|
{
|
|
"html": "<p>Nylas uses <a href=\"http://jasmine.github.io/1.3/introduction.html\">Jasmine</a> as its spec framework. As a package developer, you can write specs using Jasmine 1.3 and get some quick wins. Jasmine specs can be run in N1 directly from the Developer menu, and the test environment provides you with helpful stubs. You can also require your own test framework, or use Jasmine for integration tests and your own framework for your existing business logic.</p>\n<p>This documentation describes using <a href=\"http://jasmine.github.io/1.3/introduction.html\">Jasmine 1.3</a> to write specs for a Nylas package.</p>\n<h3 id=\"running-specs\">Running Specs</h3>\n<p>You can run your package specs from <code>Developer > Run Package Specs...</code>. Once you've opened the spec window, you can see output and re-run your specs by clicking <code>Reload Specs</code>.</p>\n<h3 id=\"writing-specs\">Writing Specs</h3>\n<p>To create specs, place <code>js</code>, <code>coffee</code>, or <code>cjsx</code> files in the <code>spec</code> directory of your package. Spec files must end with the <code>-spec</code> suffix.</p>\n<p>Here's an annotated look at a typical Jasmine spec:</p>\n<pre><code class=\"lang-coffee\"><span class=\"hljs-comment\"># The `describe` method takes two arguments, a description and a function. If the description</span>\n<span class=\"hljs-comment\"># explains a behavior it typically begins with `when`; if it is more like a unit test it begins</span>\n<span class=\"hljs-comment\"># with the method name.</span>\ndescribe <span class=\"hljs-string\">\"when a test is written\"</span>,<span class=\"hljs-function\"> -></span>\n\n <span class=\"hljs-comment\"># The `it` method also takes two arguments, a description and a function. Try and make the</span>\n <span class=\"hljs-comment\"># description flow with the `it` method. For example, a description of `this should work`</span>\n <span class=\"hljs-comment\"># doesn't read well as `it this should work`. But a description of `should work` sounds</span>\n <span class=\"hljs-comment\"># great as `it should work`.</span>\n <span class=\"hljs-literal\">it</span> <span class=\"hljs-string\">\"has some expectations that should pass\"</span>,<span class=\"hljs-function\"> -></span>\n\n <span class=\"hljs-comment\"># The best way to learn about expectations is to read the Jasmine documentation:</span>\n <span class=\"hljs-comment\"># http://jasmine.github.io/1.3/introduction.html#section-Expectations</span>\n <span class=\"hljs-comment\"># Below is a simple example.</span>\n\n expect(<span class=\"hljs-string\">\"apples\"</span>).toEqual(<span class=\"hljs-string\">\"apples\"</span>)\n expect(<span class=\"hljs-string\">\"oranges\"</span>).<span class=\"hljs-keyword\">not</span>.toEqual(<span class=\"hljs-string\">\"apples\"</span>)\n\ndescribe <span class=\"hljs-string\">\"Editor::moveUp\"</span>,<span class=\"hljs-function\"> -></span>\n ...\n</code></pre>\n<h4 id=\"asynchronous-spcs\">Asynchronous Spcs</h4>\n<p>Writing Asynchronous specs can be tricky at first, but a combination of spec helpers can make things easy. Here are a few quick examples:</p>\n<h5 id=\"promises\">Promises</h5>\n<p>You can use the global <code>waitsForPromise</code> function to make sure that the test does not complete until the returned promise has finished, and run your expectations in a chained promise.</p>\n<pre><code class=\"lang-coffee\"> describe <span class=\"hljs-string\">\"when requesting a Draft Session\"</span>, ->\n it <span class=\"hljs-string\">\"a session with the correct ID is returned\"</span>, ->\n waitsForPromise ->\n DraftStore.<span class=\"hljs-function\"><span class=\"hljs-title\">sessionForLocalId</span><span class=\"hljs-params\">(<span class=\"hljs-string\">'123'</span>)</span></span><span class=\"hljs-class\">.then</span> (session) ->\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(session.id)</span></span>.<span class=\"hljs-function\"><span class=\"hljs-title\">toBe</span><span class=\"hljs-params\">(<span class=\"hljs-string\">'123'</span>)</span></span>\n</code></pre>\n<p>This method can be used in the <code>describe</code>, <code>it</code>, <code>beforeEach</code> and <code>afterEach</code> functions.</p>\n<pre><code class=\"lang-coffee\">describe <span class=\"hljs-string\">\"when we open a file\"</span>, ->\n beforeEach ->\n waitsForPromise ->\n atom<span class=\"hljs-class\">.workspace</span><span class=\"hljs-class\">.open</span> <span class=\"hljs-string\">'c.coffee'</span>\n\n it <span class=\"hljs-string\">\"should be opened in an editor\"</span>, ->\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(atom.workspace.getActiveTextEditor()</span></span>.<span class=\"hljs-function\"><span class=\"hljs-title\">getPath</span><span class=\"hljs-params\">()</span></span>)<span class=\"hljs-class\">.toContain</span> <span class=\"hljs-string\">'c.coffee'</span>\n</code></pre>\n<p>If you need to wait for multiple promises use a new <code>waitsForPromise</code> function for each promise. (Caution: Without <code>beforeEach</code> this example will fail!)</p>\n<pre><code class=\"lang-coffee\">describe <span class=\"hljs-string\">\"waiting for the packages to load\"</span>, ->\n\n beforeEach ->\n waitsForPromise ->\n atom<span class=\"hljs-class\">.workspace</span><span class=\"hljs-class\">.open</span>(<span class=\"hljs-string\">'sample.js'</span>)\n waitsForPromise ->\n atom<span class=\"hljs-class\">.packages</span><span class=\"hljs-class\">.activatePackage</span>(<span class=\"hljs-string\">'tabs'</span>)\n waitsForPromise ->\n atom<span class=\"hljs-class\">.packages</span><span class=\"hljs-class\">.activatePackage</span>(<span class=\"hljs-string\">'tree-view'</span>)\n\n it <span class=\"hljs-string\">'should have waited long enough'</span>, ->\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(atom.packages.isPackageActive(<span class=\"hljs-string\">'tabs'</span>)</span></span>)<span class=\"hljs-class\">.toBe</span> true\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(atom.packages.isPackageActive(<span class=\"hljs-string\">'tree-view'</span>)</span></span>)<span class=\"hljs-class\">.toBe</span> true\n</code></pre>\n<h4 id=\"asynchronous-functions-with-callbacks\">Asynchronous functions with callbacks</h4>\n<p>Specs for asynchronous functions can be done using the <code>waitsFor</code> and <code>runs</code> functions. A simple example.</p>\n<pre><code class=\"lang-coffee\">describe <span class=\"hljs-string\">\"fs.readdir(path, cb)\"</span>, ->\n it <span class=\"hljs-string\">\"is async\"</span>, ->\n spy = jasmine.<span class=\"hljs-function\"><span class=\"hljs-title\">createSpy</span><span class=\"hljs-params\">(<span class=\"hljs-string\">'fs.readdirSpy'</span>)</span></span>\n\n fs.<span class=\"hljs-function\"><span class=\"hljs-title\">readdir</span><span class=\"hljs-params\">(<span class=\"hljs-string\">'/tmp/example'</span>, spy)</span></span>\n waitsFor ->\n spy<span class=\"hljs-class\">.callCount</span> > <span class=\"hljs-number\">0</span>\n runs ->\n exp = [null, [<span class=\"hljs-string\">'example.coffee'</span>]]\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(spy.mostRecentCall.args)</span></span><span class=\"hljs-class\">.toEqual</span> exp\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(spy)</span></span>.<span class=\"hljs-function\"><span class=\"hljs-title\">toHaveBeenCalledWith</span><span class=\"hljs-params\">(null, [<span class=\"hljs-string\">'example.coffee'</span>])</span></span>\n</code></pre>\n<p>For a more detailed documentation on asynchronous tests please visit the <a href=\"http://jasmine.github.io/1.3/introduction.html#section-Asynchronous_Support)[Jasmine\">http://jasmine.github.io/1.3/introduction.html#section-Asynchronous_Support)[Jasmine</a> documentation].</p>\n<h4 id=\"tips-for-debugging-specs\">Tips for Debugging Specs</h4>\n<p>To run a limited subset of specs use the <code>fdescribe</code> or <code>fit</code> methods. You can use those to focus a single spec or several specs. In the example above, focusing an individual spec looks like this:</p>\n<pre><code class=\"lang-coffee\">describe <span class=\"hljs-string\">\"when a test is written\"</span>, ->\n fit <span class=\"hljs-string\">\"has some expectations that should pass\"</span>, ->\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(<span class=\"hljs-string\">\"apples\"</span>)</span></span>.<span class=\"hljs-function\"><span class=\"hljs-title\">toEqual</span><span class=\"hljs-params\">(<span class=\"hljs-string\">\"apples\"</span>)</span></span>\n <span class=\"hljs-function\"><span class=\"hljs-title\">expect</span><span class=\"hljs-params\">(<span class=\"hljs-string\">\"oranges\"</span>)</span></span><span class=\"hljs-class\">.not</span><span class=\"hljs-class\">.toEqual</span>(<span class=\"hljs-string\">\"apples\"</span>)\n</code></pre>\n",
|
|
"meta": {
|
|
"Title": "Writing Specs",
|
|
"TitleHidden": true,
|
|
"Section": "Guides",
|
|
"Order": 7,
|
|
"title": "Writing Specs",
|
|
"titlehidden": true,
|
|
"section": "Guides",
|
|
"order": 7
|
|
},
|
|
"name": "Writing Specs",
|
|
"filename": "WritingSpecs.md",
|
|
"link": "WritingSpecs.html"
|
|
},
|
|
{
|
|
"html": "<h3 id=\"do-i-have-to-use-react-\">Do I have to use React?</h3>\n<p>The short answer is yes, you need to use React. The {ComponentRegistry} expects React components, so you'll need to create them to extend the N1 interface.</p>\n<p>However, if you have significant code already written in another framework, like Angular or Backbone, it's possible to attach your application to a React component. See <a href=\"https://github.com/davidchang/ngReact/issues/80\">https://github.com/davidchang/ngReact/issues/80</a>.</p>\n<h3 id=\"can-i-write-a-package-that-does-x-\">Can I write a package that does X?</h3>\n<p>If you don't find documentation for the part of N1 you want to extend, let us know! We're constantly working to enable new workflows by making more of the application extensible.</p>\n<h3 id=\"can-i-distribute-my-package-\">Can I distribute my package?</h3>\n<p>Yes! We'll be sharing more information about publishing packages in the coming months. However, you can already publish and share packages by following the steps below:</p>\n<ol>\n<li><p>Create a Github repository for your package, and publish a <code>Tag</code> to the repository matching the version number in your <code>package.json</code> file. (Ex: <code>0.1.0</code>)</p>\n</li>\n<li><p>Make the CURL request below to the package manager server to register your package:</p>\n<pre><code> curl -<span class=\"hljs-keyword\">H</span> <span class=\"hljs-string\">\"Content-Type:application/json\"</span> -X <span class=\"hljs-keyword\">POST</span> -<span class=\"hljs-keyword\">d</span> '{<span class=\"hljs-string\">\"repository\"</span>:<span class=\"hljs-string\">\"https://github.com/<username>/<repo>\"</span>}' https:<span class=\"hljs-comment\">//edgehill-packages.nylas.com/api/packages</span>\n</code></pre></li>\n<li><p>Your package will now appear when users visit the N1 settings page and search for community packages.</p>\n</li>\n</ol>\n<p>Note: In the near future, we'll be formalizing the process of distributing packages, and packages you publish now may need to be resubmitted.</p>\n",
|
|
"meta": {
|
|
"Title": "FAQ",
|
|
"Section": "Guides",
|
|
"Order": 10,
|
|
"title": "FAQ",
|
|
"section": "Guides",
|
|
"order": 10
|
|
},
|
|
"name": "FAQ",
|
|
"filename": "FAQ.md",
|
|
"link": "FAQ.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Sample Code",
|
|
"description":"Sample plugins to give an idea of what you can build on N1.",
|
|
"link": "https://nylas.github.io/N1/examples",
|
|
"external": true,
|
|
"items": [
|
|
{
|
|
"name": "Filters",
|
|
"link": "https://github.com/nylas/N1/tree/master/examples/N1-Filters",
|
|
"external": true
|
|
},
|
|
{
|
|
"name": "Github Contact Cards",
|
|
"link": "https://github.com/nylas/N1/tree/master/examples/N1-Github-Contact-Card-Section",
|
|
"external": true
|
|
},
|
|
{
|
|
"name": "Personal Level Icons",
|
|
"link": "https://github.com/nylas/N1/tree/master/examples/N1-Personal-Level-Indicators",
|
|
"external": true
|
|
},
|
|
{
|
|
"name": "Phishing Detection",
|
|
"link": "https://github.com/nylas/N1/tree/master/examples/N1-Phishing-Detection",
|
|
"external": true
|
|
},
|
|
{
|
|
"name": "Translate",
|
|
"link": "https://github.com/nylas/N1/tree/master/examples/N1-Composer-Translate",
|
|
"external": true
|
|
},
|
|
{
|
|
"name": "Send Availability",
|
|
"link": "https://github.com/nylas/N1/tree/master/examples/N1-Send-Availability",
|
|
"external": true
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "API Reference",
|
|
"description":"Detailed documentation on all the classes and methods in the API.",
|
|
"items": [
|
|
{
|
|
"name": "General",
|
|
"items": [
|
|
{
|
|
"name": "Actions",
|
|
"link": "Actions.html"
|
|
},
|
|
{
|
|
"name": "Atom",
|
|
"link": "Atom.html"
|
|
},
|
|
{
|
|
"name": "BufferedNodeProcess",
|
|
"link": "BufferedNodeProcess.html"
|
|
},
|
|
{
|
|
"name": "BufferedProcess",
|
|
"link": "BufferedProcess.html"
|
|
},
|
|
{
|
|
"name": "ChangeFolderTask",
|
|
"link": "ChangeFolderTask.html"
|
|
},
|
|
{
|
|
"name": "ChangeLabelsTask",
|
|
"link": "ChangeLabelsTask.html"
|
|
},
|
|
{
|
|
"name": "Config",
|
|
"link": "Config.html"
|
|
},
|
|
{
|
|
"name": "DraggableImg",
|
|
"link": "DraggableImg.html"
|
|
},
|
|
{
|
|
"name": "FocusTrackingRegion",
|
|
"link": "FocusTrackingRegion.html"
|
|
},
|
|
{
|
|
"name": "Switch",
|
|
"link": "Switch.html"
|
|
},
|
|
{
|
|
"name": "Task",
|
|
"link": "Task.html"
|
|
},
|
|
{
|
|
"name": "TaskQueueStatusStore",
|
|
"link": "TaskQueueStatusStore.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Component Kit",
|
|
"items": [
|
|
{
|
|
"name": "EventedIFrame",
|
|
"link": "EventedIFrame.html"
|
|
},
|
|
{
|
|
"name": "Flexbox",
|
|
"link": "Flexbox.html"
|
|
},
|
|
{
|
|
"name": "InjectedComponent",
|
|
"link": "InjectedComponent.html"
|
|
},
|
|
{
|
|
"name": "InjectedComponentSet",
|
|
"link": "InjectedComponentSet.html"
|
|
},
|
|
{
|
|
"name": "Menu",
|
|
"link": "Menu.html"
|
|
},
|
|
{
|
|
"name": "MenuItem",
|
|
"link": "MenuItem.html"
|
|
},
|
|
{
|
|
"name": "MenuNameEmailItem",
|
|
"link": "MenuNameEmailItem.html"
|
|
},
|
|
{
|
|
"name": "MultiselectActionBar",
|
|
"link": "MultiselectActionBar.html"
|
|
},
|
|
{
|
|
"name": "MultiselectList",
|
|
"link": "MultiselectList.html"
|
|
},
|
|
{
|
|
"name": "Popover",
|
|
"link": "Popover.html"
|
|
},
|
|
{
|
|
"name": "ResizableRegion",
|
|
"link": "ResizableRegion.html"
|
|
},
|
|
{
|
|
"name": "RetinaImg",
|
|
"link": "RetinaImg.html"
|
|
},
|
|
{
|
|
"name": "Spinner",
|
|
"link": "Spinner.html"
|
|
},
|
|
{
|
|
"name": "TimeoutTransitionGroupChild",
|
|
"link": "TimeoutTransitionGroupChild.html"
|
|
},
|
|
{
|
|
"name": "UnsafeComponent",
|
|
"link": "UnsafeComponent.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Models",
|
|
"items": [
|
|
{
|
|
"name": "Account",
|
|
"link": "Account.html"
|
|
},
|
|
{
|
|
"name": "Calendar",
|
|
"link": "Calendar.html"
|
|
},
|
|
{
|
|
"name": "Contact",
|
|
"link": "Contact.html"
|
|
},
|
|
{
|
|
"name": "File",
|
|
"link": "File.html"
|
|
},
|
|
{
|
|
"name": "Folder",
|
|
"link": "Folder.html"
|
|
},
|
|
{
|
|
"name": "Label",
|
|
"link": "Label.html"
|
|
},
|
|
{
|
|
"name": "Message",
|
|
"link": "Message.html"
|
|
},
|
|
{
|
|
"name": "Model",
|
|
"link": "Model.html"
|
|
},
|
|
{
|
|
"name": "Thread",
|
|
"link": "Thread.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Stores",
|
|
"items": [
|
|
{
|
|
"name": "AccountStore",
|
|
"link": "AccountStore.html"
|
|
},
|
|
{
|
|
"name": "ComponentRegistry",
|
|
"link": "ComponentRegistry.html"
|
|
},
|
|
{
|
|
"name": "ContactStore",
|
|
"link": "ContactStore.html"
|
|
},
|
|
{
|
|
"name": "EventStore",
|
|
"link": "EventStore.html"
|
|
},
|
|
{
|
|
"name": "FocusedContentStore",
|
|
"link": "FocusedContentStore.html"
|
|
},
|
|
{
|
|
"name": "MessageStoreExtension",
|
|
"link": "MessageStoreExtension.html"
|
|
},
|
|
{
|
|
"name": "TaskQueue",
|
|
"link": "TaskQueue.html"
|
|
},
|
|
{
|
|
"name": "WorkspaceStore",
|
|
"link": "WorkspaceStore.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Database",
|
|
"items": [
|
|
{
|
|
"name": "Attribute",
|
|
"link": "Attribute.html"
|
|
},
|
|
{
|
|
"name": "AttributeBoolean",
|
|
"link": "AttributeBoolean.html"
|
|
},
|
|
{
|
|
"name": "AttributeCollection",
|
|
"link": "AttributeCollection.html"
|
|
},
|
|
{
|
|
"name": "AttributeDateTime",
|
|
"link": "AttributeDateTime.html"
|
|
},
|
|
{
|
|
"name": "AttributeJoinedData",
|
|
"link": "AttributeJoinedData.html"
|
|
},
|
|
{
|
|
"name": "AttributeNumber",
|
|
"link": "AttributeNumber.html"
|
|
},
|
|
{
|
|
"name": "AttributeObject",
|
|
"link": "AttributeObject.html"
|
|
},
|
|
{
|
|
"name": "AttributeServerId",
|
|
"link": "AttributeServerId.html"
|
|
},
|
|
{
|
|
"name": "AttributeString",
|
|
"link": "AttributeString.html"
|
|
},
|
|
{
|
|
"name": "DatabaseStore",
|
|
"link": "DatabaseStore.html"
|
|
},
|
|
{
|
|
"name": "DatabaseView",
|
|
"link": "DatabaseView.html"
|
|
},
|
|
{
|
|
"name": "Matcher",
|
|
"link": "Matcher.html"
|
|
},
|
|
{
|
|
"name": "ModelQuery",
|
|
"link": "ModelQuery.html"
|
|
},
|
|
{
|
|
"name": "SortOrder",
|
|
"link": "SortOrder.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Drafts",
|
|
"items": [
|
|
{
|
|
"name": "DraftChangeSet",
|
|
"link": "DraftChangeSet.html"
|
|
},
|
|
{
|
|
"name": "DraftStore",
|
|
"link": "DraftStore.html"
|
|
},
|
|
{
|
|
"name": "DraftStoreExtension",
|
|
"link": "DraftStoreExtension.html"
|
|
},
|
|
{
|
|
"name": "DraftStoreProxy",
|
|
"link": "DraftStoreProxy.html"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "Atom",
|
|
"items": [
|
|
{
|
|
"name": "Clipboard",
|
|
"link": "Clipboard.html"
|
|
},
|
|
{
|
|
"name": "Color",
|
|
"link": "Color.html"
|
|
},
|
|
{
|
|
"name": "CommandRegistry",
|
|
"link": "CommandRegistry.html"
|
|
},
|
|
{
|
|
"name": "MenuManager",
|
|
"link": "MenuManager.html"
|
|
},
|
|
{
|
|
"name": "PackageManager",
|
|
"link": "PackageManager.html"
|
|
},
|
|
{
|
|
"name": "ScopeDescriptor",
|
|
"link": "ScopeDescriptor.html"
|
|
},
|
|
{
|
|
"name": "StyleManager",
|
|
"link": "StyleManager.html"
|
|
},
|
|
{
|
|
"name": "ThemeManager",
|
|
"link": "ThemeManager.html"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
} |