weex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject incubator-weex git commit: * [jsfm] deep normalize the options when calling native module
Date Wed, 09 May 2018 03:07:51 GMT
Repository: incubator-weex
Updated Branches:
  refs/heads/master c6a8d29ad -> 4b9a9daac


* [jsfm] deep normalize the options when calling native module


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

Branch: refs/heads/master
Commit: 4b9a9daac9de5c2e2f4b08205e82a3b96e88f960
Parents: c6a8d29
Author: Hanks <zhanghan.me@gmail.com>
Authored: Wed May 9 11:02:49 2018 +0800
Committer: Hanks <zhanghan.me@gmail.com>
Committed: Wed May 9 11:02:49 2018 +0800

----------------------------------------------------------------------
 runtime/bridge/TaskCenter.js | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4b9a9daa/runtime/bridge/TaskCenter.js
----------------------------------------------------------------------
diff --git a/runtime/bridge/TaskCenter.js b/runtime/bridge/TaskCenter.js
index c2652c0..002a69a 100644
--- a/runtime/bridge/TaskCenter.js
+++ b/runtime/bridge/TaskCenter.js
@@ -67,7 +67,7 @@ export class TaskCenter {
    * @param  {any}        v
    * @return {primitive}
    */
-  normalize (v) {
+  normalize (v, deep = false) {
     const type = typof(v)
     if (v && v instanceof Element) {
       return v.ref
@@ -78,13 +78,29 @@ export class TaskCenter {
     if (type === 'Function') {
       return this.callbackManager.add(v).toString()
     }
+    if (deep) {
+      if (type === 'Object') {
+        const object = {}
+        for (const key in v) {
+          object[key] = this.normalize(v[key], true)
+        }
+        return object
+      }
+      if (type === 'Array') {
+        return v.map(item => this.normalize(item, true))
+      }
+    }
     return normalizePrimitive(v)
   }
 
   send (type, params, args, options) {
     const { action, component, ref, module, method } = params
 
+    // normalize args and options
     args = args.map(arg => this.normalize(arg))
+    if (typof(options) === 'Object') {
+      options = this.normalize(options, true)
+    }
 
     switch (type) {
       case 'dom':


Mime
View raw message