Skip to content

Commit

Permalink
transfer-dom: Do not re-render on event:componentUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
airyland committed Jul 7, 2017
1 parent 442cbec commit 83f9eb3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/directives/transfer-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,38 @@ import objectAssign from 'object-assign'
*/
function getTarget (node) {
if (node === void 0) {
node = document.body
return document.body
}
if (node === true) { return document.body }

if (typeof node === 'string' && node.indexOf('?') === 0) {
return document.body
} else if (typeof node === 'string' && node.indexOf('?') > 0) {
node = node.split('?')[0]
}

if (node === 'body' || node === true) {
return document.body
}

return node instanceof window.Node ? node : document.querySelector(node)
}

function getShouldUpdate (node) {
// do not updated by default
if (!node) {
return false
}
if (typeof node === 'string' && node.indexOf('?') > 0) {
try {
const config = JSON.parse(node.split('?')[1])
return config.autoUpdate || false
} catch (e) {
return false
}
}
return false
}

const directive = {
inserted (el, { value }, vnode) {
el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom'
Expand All @@ -36,6 +62,10 @@ const directive = {
}
},
componentUpdated (el, { value }) {
const shouldUpdate = getShouldUpdate(value)
if (!shouldUpdate) {
return
}
// need to make sure children are done updating (vs. `update`)
var ref$1 = el.__transferDomData
// homes.get(el)
Expand Down
5 changes: 5 additions & 0 deletions src/directives/transfer-dom/metas.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
changes:
next:
en:
- '[enhance] Do not re-render on event:componentUpdated'
zh-CN:
- '[enhance] 默认不在组件内容更新时自动重新渲染,修复 popup-picker 关闭闪现体验问题'
v2.2.0:
en:
- '[enhance] Support simple entry name: TransferDom'
Expand Down

0 comments on commit 83f9eb3

Please sign in to comment.