From e6ca36b9b1561973b012a2b165beade4945ace68 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Mon, 30 Mar 2015 21:53:08 +0000 Subject: [PATCH] update website --- docs/nativemodulesios.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/nativemodulesios.html b/docs/nativemodulesios.html index 8a5ae1b568a..62e32a00c8d 100644 --- a/docs/nativemodulesios.html +++ b/docs/nativemodulesios.html @@ -48,12 +48,21 @@ CalendarManager.}

The same way if the operation can take a long time to complete, the native module should not block. It is a good idea to use dispatch_async to schedule expensive work on background queue.

Exporting constants #

Native module can export constants that are instantly available to JavaScript at runtime. This is useful to export some initial data that would otherwise require a bridge round-trip.

- (NSDictionary *)constantsToExport { return @{ @"firstDayOfTheWeek": @"Monday" }; -}

JavaScript can use this value right away:

console.log(CalendarManager.firstDayOfTheWeek);

Note that the constants are exported only at initialization time, so if you change constantsToExport value at runtime it won't affect JavaScript environment.

Sending events to JavaScript #

The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use eventDispatcher:

- (void)calendarEventReminderReceived:(NSNotification *)notification +}

JavaScript can use this value right away:

console.log(CalendarManager.firstDayOfTheWeek);

Note that the constants are exported only at initialization time, so if you change constantsToExport value at runtime it won't affect JavaScript environment.

Sending events to JavaScript #

The native module can signal events to JavaScript without being invoked directly. The easiest way to do this is to use eventDispatcher:

#import "RCTBridge.h" +#import "RCTEventDispatcher.h" + +@implementation CalendarManager + +@synthesize bridge = _bridge; + +- (void)calendarEventReminderReceived:(NSNotification *)notification { NSString *eventName = notification.userInfo[@"name"]; [self.bridge.eventDispatcher sendAppEventWithName:@"EventReminder" body:@{@"name": eventName}]; -}

JavaScript code can subscribe to these events:

var subscription = DeviceEventEmitter.addListener( +} + +@end

JavaScript code can subscribe to these events:

var subscription = DeviceEventEmitter.addListener( 'EventReminder', (reminder) => console.log(reminder.name) );