mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
code cleanup
This commit is contained in:
parent
56607f081a
commit
7c24229fd7
@ -1,18 +1,22 @@
|
||||
var booleanAttrs = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "compact", "controls", "declare",
|
||||
"default", "defaultchecked", "defaultmuted", "defaultselected", "defer", "disabled", "draggable",
|
||||
"enabled", "formnovalidate", "hidden", "indeterminate", "inert", "ismap", "itemscope", "loop", "multiple",
|
||||
"muted", "nohref", "noresize", "noshade", "novalidate", "nowrap", "open", "pauseonexit", "readonly",
|
||||
"required", "reversed", "scoped", "seamless", "selected", "sortable", "spellcheck", "translate",
|
||||
"truespeed", "typemustmatch", "visible"]
|
||||
const booleanAttrs = [
|
||||
"allowfullscreen", "async", "autofocus", "autoplay", "checked", "compact", "controls", "declare",
|
||||
"default", "defaultchecked", "defaultmuted", "defaultselected", "defer", "disabled", "draggable",
|
||||
"enabled", "formnovalidate", "hidden", "indeterminate", "inert", "ismap", "itemscope", "loop", "multiple",
|
||||
"muted", "nohref", "noresize", "noshade", "novalidate", "nowrap", "open", "pauseonexit", "readonly",
|
||||
"required", "reversed", "scoped", "seamless", "selected", "sortable", "spellcheck", "translate",
|
||||
"truespeed", "typemustmatch", "visible"
|
||||
]
|
||||
|
||||
var booleanAttrsDict = {}
|
||||
for(var i=0, len = booleanAttrs.length; i < len; i++) {
|
||||
const booleanAttrsDict = {}
|
||||
for (let i = 0, len = booleanAttrs.length; i < len; i++) {
|
||||
booleanAttrsDict[booleanAttrs[i]] = true
|
||||
}
|
||||
|
||||
function updateAttrs(oldVnode, vnode) {
|
||||
var key, cur, old, elm = vnode.elm,
|
||||
oldAttrs = oldVnode.data.attrs || {}, attrs = vnode.data.attrs || {}
|
||||
function updateAttr (oldVnode, vnode) {
|
||||
let key, cur, old
|
||||
const elm = vnode.elm
|
||||
const oldAttrs = oldVnode.data.attrs || {}
|
||||
const attrs = vnode.data.attrs || {}
|
||||
|
||||
// update modified attributes, add new attributes
|
||||
for (key in attrs) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
function arrInvoker(arr) {
|
||||
return function() {
|
||||
// Special case when length is two, for performance
|
||||
arr.length === 2 ? arr[0](arr[1]) : arr[0].apply(undefined, arr.slice(1))
|
||||
arr.length === 2
|
||||
? arr[0](arr[1])
|
||||
: arr[0].apply(undefined, arr.slice(1))
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,8 +12,10 @@ function fnInvoker(o) {
|
||||
}
|
||||
|
||||
function updateEventListeners(oldVnode, vnode) {
|
||||
var name, cur, old, elm = vnode.elm,
|
||||
oldOn = oldVnode.data.on || {}, on = vnode.data.on
|
||||
let name, cur, old
|
||||
const elm = vnode.elm
|
||||
const oldOn = oldVnode.data.on || {}
|
||||
const on = vnode.data.on
|
||||
if (!on) return
|
||||
for (name in on) {
|
||||
cur = on[name]
|
||||
|
@ -1,6 +1,9 @@
|
||||
function updateProps(oldVnode, vnode) {
|
||||
var key, cur, old, elm = vnode.elm,
|
||||
oldProps = oldVnode.data.props || {}, props = vnode.data.props || {}
|
||||
let key, cur, old
|
||||
const elm = vnode.elm
|
||||
const oldProps = oldVnode.data.props || {}
|
||||
const props = vnode.data.props || {}
|
||||
|
||||
for (key in oldProps) {
|
||||
if (!props[key]) {
|
||||
delete elm[key]
|
||||
|
@ -1,19 +1,12 @@
|
||||
// TODO:
|
||||
// - remove animation related bits
|
||||
// - include prefix sniffing of v-bind:style
|
||||
|
||||
var raf = (typeof window !== 'undefined' && window.requestAnimationFrame) || setTimeout
|
||||
var nextFrame = function(fn) { raf(function() { raf(fn) }) }
|
||||
|
||||
function setNextFrame(obj, prop, val) {
|
||||
nextFrame(function() { obj[prop] = val })
|
||||
}
|
||||
|
||||
function updateStyle(oldVnode, vnode) {
|
||||
var cur, name, elm = vnode.elm,
|
||||
oldStyle = oldVnode.data.style || {},
|
||||
style = vnode.data.style || {},
|
||||
oldHasDel = 'delayed' in oldStyle
|
||||
let cur, name
|
||||
const elm = vnode.elm
|
||||
const oldStyle = oldVnode.data.style || {}
|
||||
const style = vnode.data.style || {}
|
||||
|
||||
for (name in oldStyle) {
|
||||
if (!style[name]) {
|
||||
elm.style[name] = ''
|
||||
@ -21,53 +14,13 @@ function updateStyle(oldVnode, vnode) {
|
||||
}
|
||||
for (name in style) {
|
||||
cur = style[name]
|
||||
if (name === 'delayed') {
|
||||
for (name in style.delayed) {
|
||||
cur = style.delayed[name]
|
||||
if (!oldHasDel || cur !== oldStyle.delayed[name]) {
|
||||
setNextFrame(elm.style, name, cur)
|
||||
}
|
||||
}
|
||||
} else if (name !== 'remove' && cur !== oldStyle[name]) {
|
||||
if (cur !== oldStyle[name]) {
|
||||
elm.style[name] = cur
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function applyDestroyStyle(vnode) {
|
||||
var style, name, elm = vnode.elm, s = vnode.data.style
|
||||
if (!s || !(style = s.destroy)) return
|
||||
for (name in style) {
|
||||
elm.style[name] = style[name]
|
||||
}
|
||||
}
|
||||
|
||||
function applyRemoveStyle(vnode, rm) {
|
||||
var s = vnode.data.style
|
||||
if (!s || !s.remove) {
|
||||
rm()
|
||||
return
|
||||
}
|
||||
var name, elm = vnode.elm, idx, i = 0, maxDur = 0,
|
||||
compStyle, style = s.remove, amount = 0, applied = []
|
||||
for (name in style) {
|
||||
applied.push(name)
|
||||
elm.style[name] = style[name]
|
||||
}
|
||||
compStyle = getComputedStyle(elm)
|
||||
var props = compStyle['transition-property'].split(', ')
|
||||
for (; i < props.length; ++i) {
|
||||
if(applied.indexOf(props[i]) !== -1) amount++
|
||||
}
|
||||
elm.addEventListener('transitionend', function(ev) {
|
||||
if (ev.target === elm) --amount
|
||||
if (amount === 0) rm()
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
create: updateStyle,
|
||||
update: updateStyle,
|
||||
destroy: applyDestroyStyle,
|
||||
remove: applyRemoveStyle
|
||||
update: updateStyle
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user