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

Commit

Permalink
+ [jsfm] Support batch update styles and attributes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hanks10100 committed Oct 24, 2017
1 parent aaa1bdb commit 30716b6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions html5/runtime/vdom/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 30716b6

Please sign in to comment.