weex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinji...@apache.org
Subject [10/50] [abbrv] incubator-weex git commit: * [ios] format callback ret data
Date Tue, 24 Jan 2017 08:21:21 GMT
* [ios] format callback ret data


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/83c747f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/83c747f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/83c747f3

Branch: refs/heads/master
Commit: 83c747f318a3d3bf5df9b8493c8f2cc65bab39f7
Parents: 1fb2e0a
Author: acton393 <zhangxing610321@gmail.com>
Authored: Tue Jan 10 22:21:12 2017 +0800
Committer: acton393 <zhangxing610321@gmail.com>
Committed: Tue Jan 10 22:21:12 2017 +0800

----------------------------------------------------------------------
 ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m |  4 +--
 ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m   | 30 ++++++++++++++------
 .../Sources/Model/WXSDKInstance_private.h       |  5 ++--
 3 files changed, 26 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/83c747f3/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m b/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
index 37a75a3..de07eca 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXModuleMethod.m
@@ -49,10 +49,10 @@
     if (![moduleInstance respondsToSelector:selector]) {
         // if not implement the selector, then dispatch default module method
         if ([self.methodName isEqualToString:@"addEventListener"]) {
-            [self.instance _addModuleEventObserversWithArguments:self.arguments moduleClassName:NSStringFromClass(moduleClass)];
+            [self.instance _addModuleEventObserversWithModuleMethod:self];
         }
         if ([self.methodName isEqualToString:@"removeAllEventListeners"]) {
-            [self.instance _removeModuleEventObserverWithArguments:self.arguments moduleClassName:NSStringFromClass(moduleClass)];
+            [self.instance _removeModuleEventObserverWithModuleMethod:self];
         }
         return nil;
     }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/83c747f3/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index f77e9d5..0220ace 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -307,7 +307,7 @@ typedef enum : NSUInteger {
     [data setObject:[NSString stringWithFormat:@"%ld",(long)state] forKey:@"state"];
     //[[WXSDKManager bridgeMgr] updateState:self.instanceId data:data];
     
-    [[NSNotificationCenter defaultCenter]postNotificationName:WX_INSTANCE_NOTIFICATION_UPDATE_STATE
object:self userInfo:data];
+    [[NSNotificationCenter defaultCenter] postNotificationName:WX_INSTANCE_NOTIFICATION_UPDATE_STATE
object:self userInfo:data];
 }
 
 - (id)moduleForClass:(Class)moduleClass
@@ -395,28 +395,37 @@ typedef enum : NSUInteger {
 
 #pragma mark Private Methods
 
-- (void)_addModuleEventObserversWithArguments:(NSArray*)arguments moduleClassName:(NSString*)moduleClassName
+- (void)_addModuleEventObserversWith:(WXModuleMethod *)method
 {
-    if ([arguments count] < 2) {
+    if ([method.arguments count] < 2) {
         WXLogError(@"please check your method parameter!!");
         return;
     }
-    if(![arguments[0] isKindOfClass:[NSString class]]) {
+    if(![method.arguments[0] isKindOfClass:[NSString class]]) {
         // arguments[0] will be event name, so it must be a string type value here.
         return;
     }
-    NSMutableArray * methodArguments = [arguments mutableCopy];
-    if ([arguments count] == 2) {
+    NSMutableArray * methodArguments = [method.arguments mutableCopy];
+    if ([methodArguments count] == 2) {
         [methodArguments addObject:@{@"once": @false}];
     }
-    [self addModuleEventObservers:methodArguments[0] callback:methodArguments[1] option:methodArguments[2]
moduleClassName:moduleClassName];
+    if (![methodArguments[2] isKindOfClass:[NSDictionary class]]) {
+        //arguments[2] is the option value, so it must be a dictionary.
+        return;
+    }
+    Class moduleClass =  [WXModuleFactory classWithModuleName:method.moduleName];
+    NSMutableDictionary * option = [methodArguments[3] mutableCopy];
+    [option setObject:method.moduleName forKey:@"moduleName"];
+    // the value for moduleName in option is for the need of callback
+    [self addModuleEventObservers:methodArguments[0] callback:methodArguments[1] option:option
moduleClassName:NSClassFromString(moduleClass)];
 }
 
 - (void)addModuleEventObservers:(NSString*)event callback:(NSString*)callbackId option:(NSDictionary
*)option moduleClassName:(NSString*)moduleClassName
 {
     BOOL once = [[option objectForKey:@"once"] boolValue];
+    NSString * moduleName = [option objectForKey:@"moduleName"];
     NSMutableDictionary * observer = nil;
-    NSDictionary * callbackInfo = @{@"callbackId":callbackId,@"once":@(once)};
+    NSDictionary * callbackInfo = @{@"callbackId":callbackId,@"once":@(once),@"moduleName":moduleName};
     if(![self checkModuleEventRegistered:event moduleClassName:moduleClassName]) {
         //had not registered yet
         observer = [NSMutableDictionary new];
@@ -456,7 +465,10 @@ typedef enum : NSUInteger {
         NSDictionary * callbackInfo = listeners[i];
         NSString *callbackId = callbackInfo[@"callbackId"];
         BOOL once = [callbackInfo[@"once"] boolValue];
-        [[WXSDKManager bridgeMgr] callBack:self.instanceId funcId:callbackId params:userInfo[@"param"]
keepAlive:!once];
+        NSMutableDictionary * retData = @{@"type":userInfo[@"eventName"],
+                                               @"module":callbackInfo[@"moduleName"],
+                                               @"data":userInfo[@"param"]};
+        [[WXSDKManager bridgeMgr] callBack:self.instanceId funcId:callbackId params:retData
keepAlive:!once];
         // if callback function is not once, then it is keepalive
         if (once) {
             NSMutableArray * moduleEventListener = [_moduleEventObservers[userInfo[@"moduleId"]]
objectForKey:userInfo[@"eventName"]];

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/83c747f3/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
index 3505a60..0bddbf9 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance_private.h
@@ -9,6 +9,7 @@
 #import <Foundation/Foundation.h>
 #import "WXSDKInstance.h"
 #import "WXComponentManager.h"
+#import "WXModuleMethod.h"
 
 @interface WXSDKInstance ()
 
@@ -22,8 +23,8 @@
 @property (nonatomic, readonly, strong) WXComponentManager *componentManager;
 
 - (void)addModuleEventObservers:(NSString*)event callback:(NSString*)callbackId option:(NSDictionary*)option
moduleClassName:(NSString*)moduleClassName;
-- (void)_addModuleEventObserversWithArguments:(NSArray*)arguments moduleClassName:(NSString*)moduleClassName;
+- (void)_addModuleEventObserversWithModuleMethod:(WXModuleMethod*)method;
 - (void)removeModuleEventObserver:(NSString*)event moduleClassName:(NSString*)moduleClassName;
-- (void)_removeModuleEventObserverWithArguments:(NSArray*)arguments moduleClassName:(NSString*)moduleClassName;
+- (void)_removeModuleEventObserverWithModuleMethod:(WXModuleMethod*)method;
 
 @end


Mime
View raw message