update website

This commit is contained in:
Travis CI
2015-04-26 18:48:04 +00:00
parent 8ac192f224
commit ff1455af35
+9 -1
View File
@@ -47,7 +47,15 @@ CalendarManager<span class="token punctuation">.</span><span class="token functi
<span class="token punctuation">}</span></div><p>Similarly, if an operation may take a long time to complete, the native module should not block and can specify it&#x27;s own queue to run operations on. For example, the <code>RCTAsyncLocalStorage</code> module creates it&#x27;s own queue so the React queue isn&#x27;t blocked waiting on potentially slow disk access:</p><div class="prism language-javascript"><span class="token operator">-</span> <span class="token punctuation">(</span>dispatch_queue_t<span class="token punctuation">)</span>methodQueue
<span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">dispatch_queue_create<span class="token punctuation">(</span></span><span class="token string">&quot;com.facebook.React.AsyncLocalStorageQueue&quot;</span><span class="token punctuation">,</span> DISPATCH_QUEUE_SERIAL<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></div><h2><a class="anchor" name="exporting-constants"></a>Exporting Constants <a class="hash-link" href="#exporting-constants">#</a></h2><p>A native module can export constants that are immediately available to JavaScript at runtime. This is useful for communicating static data that would otherwise require a round-trip through the bridge.</p><div class="prism language-javascript"><span class="token operator">-</span> <span class="token punctuation">(</span>NSDictionary <span class="token operator">*</span><span class="token punctuation">)</span>constantsToExport
<span class="token punctuation">}</span></div><p>The specified <code>methodQueue</code> will be shared by all of the methods in your module. If <em>just one</em> of your methods is long-running (or needs to be run on a different queue than the others for some reason), you can use <code>dispatch_async</code> inside the method to perform that particular method&#x27;s code on another queue, without affecting the others:</p><div class="prism language-javascript"><span class="token function">RCT_EXPORT_METHOD<span class="token punctuation">(</span></span>doSomethingExpensive<span class="token punctuation">:</span><span class="token punctuation">(</span>NSString <span class="token operator">*</span><span class="token punctuation">)</span>param callback<span class="token punctuation">:</span><span class="token punctuation">(</span>RCTResponseSenderBlock<span class="token punctuation">)</span>callback<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
<span class="token function">dispatch_async<span class="token punctuation">(</span></span><span class="token function">dispatch_get_global_queue<span class="token punctuation">(</span></span>DISPATCH_QUEUE_PRIORITY_DEFAULT<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token operator">^</span><span class="token punctuation">{</span>
<span class="token comment" spellcheck="true"> // Call long-running code on background thread
</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token comment" spellcheck="true"> // You can invoke callback from any thread/queue
</span> <span class="token function">callback<span class="token punctuation">(</span></span>@<span class="token punctuation">[</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></div><blockquote><p><strong>NOTE</strong>: Sharing dispatch queues between modules</p><p>The <code>methodQueue</code> method will be called once when the module is initialized, and then retained by the bridge, so there is no need to retain the queue yourself, unless you wish to make use of it within your module. However, if you wish to share the same queue between multiple modules then you will need to ensure that you retain and return the same queue instance for each of them; merely returning a queue of the same name for each won&#x27;t work.</p></blockquote><h2><a class="anchor" name="exporting-constants"></a>Exporting Constants <a class="hash-link" href="#exporting-constants">#</a></h2><p>A native module can export constants that are immediately available to JavaScript at runtime. This is useful for communicating static data that would otherwise require a round-trip through the bridge.</p><div class="prism language-javascript"><span class="token operator">-</span> <span class="token punctuation">(</span>NSDictionary <span class="token operator">*</span><span class="token punctuation">)</span>constantsToExport
<span class="token punctuation">{</span>
<span class="token keyword">return</span> @<span class="token punctuation">{</span> @<span class="token string">&quot;firstDayOfTheWeek&quot;</span><span class="token punctuation">:</span> @<span class="token string">&quot;Monday&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></div><p>JavaScript can use this value right away, synchronously:</p><div class="prism language-javascript">console<span class="token punctuation">.</span><span class="token function">log<span class="token punctuation">(</span></span>CalendarManager<span class="token punctuation">.</span>firstDayOfTheWeek<span class="token punctuation">)</span><span class="token punctuation">;</span></div><p>Note that the constants are exported only at initialization time, so if you change <code>constantsToExport</code> values at runtime it won&#x27;t affect the JavaScript environment.</p><h2><a class="anchor" name="sending-events-to-javascript"></a>Sending Events to JavaScript <a class="hash-link" href="#sending-events-to-javascript">#</a></h2><p>The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use <code>eventDispatcher</code>:</p><div class="prism language-javascript">#import <span class="token string">&quot;RCTBridge.h&quot;</span>