From 30716b672b7ba951796b1b17385e484aaa68f9d9 Mon Sep 17 00:00:00 2001 From: Hanks Date: Tue, 24 Oct 2017 16:18:35 +0800 Subject: [PATCH] + [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. --- html5/runtime/vdom/Element.js | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/html5/runtime/vdom/Element.js b/html5/runtime/vdom/Element.js index 15837f2a05..01e30452b0 100644 --- a/html5/runtime/vdom/Element.js +++ b/html5/runtime/vdom/Element.js @@ -298,6 +298,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 @@ -321,6 +339,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