Return early in module update functions

pull/102/head
Evan You 9 years ago
parent c2a6570e6a
commit 69a7c72d72

@ -1,19 +1,23 @@
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",
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"];
var booleanAttrsDict = {};
for(var 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 || {};
oldAttrs = oldVnode.data.attrs, attrs = vnode.data.attrs;
if (!oldAttrs && !attrs) return;
oldAttrs = oldAttrs || {};
attrs = attrs || {};
// update modified attributes, add new attributes
for (key in attrs) {
cur = attrs[key];

@ -1,7 +1,12 @@
function updateClass(oldVnode, vnode) {
var cur, name, elm = vnode.elm,
oldClass = oldVnode.data.class || {},
klass = vnode.data.class || {};
oldClass = oldVnode.data.class,
klass = vnode.data.class;
if (!oldClass && !klass) return;
oldClass = oldClass || {};
klass = klass || {};
for (name in oldClass) {
if (!klass[name]) {
elm.classList.remove(name);

@ -1,9 +1,13 @@
function updateDataset(oldVnode, vnode) {
var elm = vnode.elm,
oldDataset = oldVnode.data.dataset || {},
dataset = vnode.data.dataset || {},
oldDataset = oldVnode.data.dataset,
dataset = vnode.data.dataset,
key
if (!oldDataset && !dataset) return;
oldDataset = oldDataset || {};
dataset = dataset || {};
for (key in oldDataset) {
if (!dataset[key]) {
delete elm.dataset[key];

@ -13,8 +13,12 @@ function fnInvoker(o) {
function updateEventListeners(oldVnode, vnode) {
var name, cur, old, elm = vnode.elm,
oldOn = oldVnode.data.on || {}, on = vnode.data.on;
if (!on) return;
oldOn = oldVnode.data.on, on = vnode.data.on;
if (!on && !oldOn) return;
on = on || {};
oldOn = oldOn || {};
for (name in on) {
cur = on[name];
old = oldOn[name];

@ -1,6 +1,11 @@
function updateProps(oldVnode, vnode) {
var key, cur, old, elm = vnode.elm,
oldProps = oldVnode.data.props || {}, props = vnode.data.props || {};
oldProps = oldVnode.data.props, props = vnode.data.props;
if (!oldProps && !props) return;
oldProps = oldProps || {};
props = props || {};
for (key in oldProps) {
if (!props[key]) {
delete elm[key];

@ -7,9 +7,14 @@ function setNextFrame(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;
oldStyle = oldVnode.data.style,
style = vnode.data.style;
if (!oldStyle && !style) return;
oldStyle = oldStyle || {};
style = style || {};
var oldHasDel = 'delayed' in oldStyle;
for (name in oldStyle) {
if (!style[name]) {
elm.style[name] = '';

Loading…
Cancel
Save