You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by da...@apache.org on 2017/10/31 04:00:10 UTC

incubator-weex git commit: + [jsfm] Support batch update styles and attributes

Repository: incubator-weex
Updated Branches:
  refs/heads/master aaa1bdbad -> 30716b672


+ [jsfm] Support batch update styles and attributes

Add `setAttrs` and `setStyles` method on `Element.prototype` to support
batch update styles and attributes. This feature can be used in the DSL
framework to optimize performance.


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

Branch: refs/heads/master
Commit: 30716b672b7ba951796b1b17385e484aaa68f9d9
Parents: aaa1bdb
Author: Hanks <zh...@gmail.com>
Authored: Tue Oct 24 16:18:35 2017 +0800
Committer: Hanks <zh...@gmail.com>
Committed: Tue Oct 24 16:18:35 2017 +0800

----------------------------------------------------------------------
 html5/runtime/vdom/Element.js | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/30716b67/html5/runtime/vdom/Element.js
----------------------------------------------------------------------
diff --git a/html5/runtime/vdom/Element.js b/html5/runtime/vdom/Element.js
index 15837f2..01e3045 100644
--- a/html5/runtime/vdom/Element.js
+++ b/html5/runtime/vdom/Element.js
@@ -299,6 +299,24 @@ export default class Element extends Node {
   }
 
   /**
+   * Set batched attributes.
+   * @param {object} batchedAttrs
+   * @param {boolean} silent
+   */
+  setAttrs (batchedAttrs, silent) {
+    // TODO: validate batched attributes
+    Object.assign(this.attr, batchedAttrs)
+    const taskCenter = getTaskCenter(this.docId)
+    if (!silent && taskCenter) {
+      taskCenter.send(
+        'dom',
+        { action: 'updateAttrs' },
+        [this.ref, batchedAttrs]
+      )
+    }
+  }
+
+  /**
    * Set a style property, and decide whether the task should be send to native.
    * @param {string} key
    * @param {string | number} value
@@ -322,6 +340,24 @@ export default class Element extends Node {
   }
 
   /**
+   * Set batched style properties.
+   * @param {object} batchedStyles
+   * @param {boolean} silent
+   */
+  setStyles (batchedStyles, silent) {
+    // TODO: validate batched styles
+    Object.assign(this.style, batchedStyles)
+    const taskCenter = getTaskCenter(this.docId)
+    if (!silent && taskCenter) {
+      taskCenter.send(
+        'dom',
+        { action: 'updateStyle' },
+        [this.ref, batchedStyles]
+      )
+    }
+  }
+
+  /**
    * Set style properties from class.
    * @param {object} classStyle
    */