]> git.gir.st - VimFx.git/blob - docs/unload.html
Merge pull request #208 from lydell/proper-modes
[VimFx.git] / docs / unload.html
1 <!DOCTYPE html> <html> <head> <title>unload.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="bootstrap.html"> bootstrap.coffee </a> <a class="source" href="chrome.html"> chrome.coffee </a> <a class="source" href="console.html"> console.coffee </a> <a class="source" href="unload.html"> unload.coffee </a> <a class="source" href="window-utils.html"> window-utils.coffee </a> <a class="source" href="button.html"> button.coffee </a> <a class="source" href="commands.html"> commands.coffee </a> <a class="source" href="events.html"> events.coffee </a> <a class="source" href="help.html"> help.coffee </a> <a class="source" href="hints.html"> hints.coffee </a> <a class="source" href="marker.html"> marker.coffee </a> <a class="source" href="prefs.html"> prefs.coffee </a> <a class="source" href="utils.html"> utils.coffee </a> <a class="source" href="vim.html"> vim.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> unload.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="nv">unload = </span><span class="nx">do</span> <span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Initialize the array of unloaders on the first usage</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">unloaders = </span><span class="p">[];</span>
2
3 <span class="k">return</span> <span class="nf">(callback, container) -&gt;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Calling with no arguments runs all the unloader callbacks</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="o">!</span><span class="nx">callback</span>
4 <span class="nx">unloader</span><span class="p">()</span> <span class="k">for</span> <span class="nx">unloader</span> <span class="k">in</span> <span class="nx">unloaders</span>
5 <span class="nv">unloaders.length = </span><span class="mi">0</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>The callback is bound to the lifetime of the container if we have one</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">else</span> <span class="k">if</span> <span class="nx">container</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Remove the unloader when the container unloads</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">container</span><span class="p">.</span><span class="nx">addEventListener</span> <span class="s">&quot;unload&quot;</span><span class="p">,</span> <span class="nx">removeUnloader</span><span class="p">,</span> <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Wrap the callback to additionally remove the unload listener</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">origCallback = </span><span class="nx">callback</span>
6 <span class="nv">callback = </span><span class="o">-&gt;</span>
7 <span class="nx">container</span><span class="p">.</span><span class="nx">removeEventListener</span> <span class="s">&quot;unload&quot;</span><span class="p">,</span> <span class="nx">removeUnloader</span><span class="p">,</span> <span class="kc">false</span>
8 <span class="nx">origCallback</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Wrap the callback in a function that ignores failures</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">unloader = </span><span class="o">-&gt;</span> <span class="k">try</span> <span class="nx">callback</span><span class="p">()</span>
9 <span class="nx">unloaders</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">unloader</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Provide a way to remove the unloader</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">removeUnloader = </span><span class="o">-&gt;</span>
10 <span class="nv">index = </span><span class="nx">unloaders</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">unloader</span>
11 <span class="k">if</span> <span class="nx">index</span> <span class="o">&gt;</span> <span class="o">-</span><span class="mi">1</span>
12 <span class="nx">unloaders</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="nx">index</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
13
14 <span class="k">return</span> <span class="nx">removeUnloader</span>
15
16 </pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Imprint / Impressum