Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 30716b6

Browse files
committed
+ [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.
1 parent aaa1bdb commit 30716b6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

html5/runtime/vdom/Element.js

+36
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,24 @@ export default class Element extends Node {
298298
}
299299
}
300300

301+
/**
302+
* Set batched attributes.
303+
* @param {object} batchedAttrs
304+
* @param {boolean} silent
305+
*/
306+
setAttrs (batchedAttrs, silent) {
307+
// TODO: validate batched attributes
308+
Object.assign(this.attr, batchedAttrs)
309+
const taskCenter = getTaskCenter(this.docId)
310+
if (!silent && taskCenter) {
311+
taskCenter.send(
312+
'dom',
313+
{ action: 'updateAttrs' },
314+
[this.ref, batchedAttrs]
315+
)
316+
}
317+
}
318+
301319
/**
302320
* Set a style property, and decide whether the task should be send to native.
303321
* @param {string} key
@@ -321,6 +339,24 @@ export default class Element extends Node {
321339
}
322340
}
323341

342+
/**
343+
* Set batched style properties.
344+
* @param {object} batchedStyles
345+
* @param {boolean} silent
346+
*/
347+
setStyles (batchedStyles, silent) {
348+
// TODO: validate batched styles
349+
Object.assign(this.style, batchedStyles)
350+
const taskCenter = getTaskCenter(this.docId)
351+
if (!silent && taskCenter) {
352+
taskCenter.send(
353+
'dom',
354+
{ action: 'updateStyle' },
355+
[this.ref, batchedStyles]
356+
)
357+
}
358+
}
359+
324360
/**
325361
* Set style properties from class.
326362
* @param {object} classStyle

0 commit comments

Comments
 (0)