Skip to content

Commit

Permalink
release v2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
roland-reed committed Feb 1, 2018
1 parent 0f3b920 commit 9d12b3a
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 345 deletions.
145 changes: 80 additions & 65 deletions dist/React.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Maintained by YMFE Copyright 2018-01-30
* Maintained by YMFE Copyright 2018-02-01
* IE9+
*/

Expand Down Expand Up @@ -648,6 +648,9 @@ function emptyElement(node) {
var child;
while (child = node.firstChild) {
emptyElement(child);
if (child === Refs.focusNode) {
Refs.focusNode = false;
}
node.removeChild(child);
}
}
Expand All @@ -659,7 +662,6 @@ function removeElement(node) {
if (!node) {
return;
}
Refs.nodeOperate = true;
if (node.nodeType === 1) {
if (isStandard) {
node.textContent = "";
Expand All @@ -673,9 +675,11 @@ function removeElement(node) {
recyclables["#text"].push(node);
}
}
if (node === Refs.focusNode) {
Refs.focusNode = false;
}
fragment.appendChild(node);
fragment.removeChild(node);
Refs.nodeOperate = false;
}

var versions = {
Expand Down Expand Up @@ -742,6 +746,17 @@ function createElement$1(vnode, p) {
return document.createElement(type);
}

function contains(a, b) {
if (b) {
while (b = b.parentNode) {
if (b === a) {
return true;
}
}
}
return false;
}

function insertElement(vnode, insertPoint) {
if (vnode._disposed) {
return;
Expand All @@ -764,9 +779,22 @@ function insertElement(vnode, insertPoint) {
if (after === dom) {
return;
}
Refs.nodeOperate = true;
if (after === null && dom === parentNode.lastChild) {
return;
}
var isElement = vnode.vtype;

var prevFocus = isElement && document.activeElement;
parentNode.insertBefore(dom, after);
Refs.nodeOperate = false;
if (isElement && prevFocus !== document.activeElement && contains(document.body, prevFocus)) {
try {
Refs.focusNode = prevFocus;
prevFocus.__inner__ = true;
prevFocus.focus();
} catch (e) {
prevFocus.__inner__ = false;
}
}
}

var topVnodes = [];
Expand Down Expand Up @@ -801,6 +829,7 @@ function disposeVnode(vnode, updateQueue, silent) {
}
}
function remove() {
this.vnode._disposed = true;
delete this.vnode.stateNode;
removeElement(this.node);
}
Expand Down Expand Up @@ -988,12 +1017,10 @@ function dispatchEvent(e, type, end) {
}
var bubble = e.type;
var dom = e.target;
if (bubble === "blur") {
if (Refs.nodeOperate) {
Refs.focusNode = dom;
Refs.type = bubble;
}
} else if (bubble === "focus") {
if ((type === "focus" || type === "blur") && e.currentTarget !== dom) {
return;
}
if (bubble === "focus") {
if (dom.__inner__) {
dom.__inner__ = false;
return;
Expand Down Expand Up @@ -1099,10 +1126,6 @@ function getBrowserName(onStr) {
return lower;
}

eventPropHooks.click = function (e) {
return !e.target.disabled;
};

/* IE6-11 chrome mousewheel wheelDetla 下 -120 上 120
firefox DOMMouseScroll detail 下3 上-3
firefox wheel detlaY 下3 上-3
Expand All @@ -1123,13 +1146,6 @@ eventHooks.wheel = function (dom) {
});
};

"blur,focus".replace(/\w+/g, function (type) {
if (!document["__" + type]) {
document["__" + type] = true;
addGlobalEvent(type, true);
}
});

/**
*
DOM通过event对象的relatedTarget属性提供了相关元素的信息。这个属性只对于mouseover和mouseout事件才包含值;
Expand All @@ -1145,17 +1161,6 @@ function getRelatedTarget(e) {
return e.relatedTarget;
}

function contains(a, b) {
if (b) {
while (b = b.parentNode) {
if (b === a) {
return true;
}
}
}
return false;
}

String("mouseenter,mouseleave").replace(/\w+/g, function (type) {
eventHooks[type] = function (dom, name) {
var mark = "__" + name;
Expand Down Expand Up @@ -1208,38 +1213,56 @@ function getLowestCommonAncestor(instA, instB) {
return null;
}

if (isTouch) {
eventHooks.click = eventHooks.clickcapture = function (dom) {
dom.onclick = dom.onclick || noop;
};
}

var specialHandles = {};
function createHandle(name, fn) {
return function (e) {
specialHandles[name] = function (e) {
if (fn && fn(e) === false) {
return;
}
dispatchEvent(e, name);
};
}

var changeHandle = createHandle("change");
var doubleClickHandle = createHandle("doubleclick");
var scrollHandle = createHandle("scroll");
createHandle("change");
createHandle("doubleclick");
createHandle("scroll");

if (isTouch) {
eventHooks.click = eventHooks.clickcapture = function (dom) {
dom.onclick = dom.onclick || noop;
};
}

eventPropHooks.click = function (e) {
return !e.target.disabled;
};

//react将text,textarea,password元素中的onChange事件当成onInput事件
eventHooks.changecapture = eventHooks.change = function (dom) {
if (/text|password/.test(dom.type)) {
addEvent(document, "input", changeHandle);
addEvent(document, "input", specialHandles.change);
}
};

eventHooks.scrollcapture = eventHooks.scroll = function (dom) {
addEvent(dom, "scroll", scrollHandle);
//这两个事件不进行全局监听
"blur,focus".replace(/\w+/g, function (type) {
globalEvents[type] = true;
createHandle(type);
eventHooks[type] = function (dom, name) {
if (modern) {
addEvent(dom, name, specialHandles[name], true);
} else {
addEvent(dom, name === "focus" ? "focusin" : "focusout", specialHandles[name]);
}
};
});

eventHooks.scroll = function (dom, name) {
addEvent(dom, name, specialHandles[name]);
};

eventHooks.doubleclick = eventHooks.doubleclickcapture = function () {
addEvent(document, "dblclick", doubleClickHandle);
eventHooks.doubleclick = function (dom, name) {
addEvent(document, "dblclick", specialHandles[name]);
};

function SyntheticEvent(event) {
Expand Down Expand Up @@ -2523,9 +2546,8 @@ CompositeUpdater.prototype = {
var nodes = collectComponentNodes(this.children);
var queue = this.insertCarrier;
nodes.forEach(function (el) {
insertElement(el, queue);
insertElement(el, queue.dom);
queue.dom = el.stateNode;
// queue.unshift(el.stateNode);
});
} else {
captureError(instance, "componentWillUpdate", [props, state, context]);
Expand Down Expand Up @@ -2614,16 +2636,6 @@ CompositeUpdater.prototype = {
if (!hasMounted) {
this.isMounted = returnTrue;
}
var node = Refs.focusNode;
if (node) {
try {
node.focus();
node.__inner__ = true;
} catch (e) {
//hack
}
delete Refs.focusNode;
}
if (this._hydrating) {
var hookName = hasMounted ? "componentDidUpdate" : "componentDidMount";
captureError(instance, hookName, this._hookArgs || []);
Expand Down Expand Up @@ -2672,7 +2684,7 @@ CompositeUpdater.prototype = {
captureError(instance, "componentWillUnmount", []);
//在执行componentWillUnmount后才将关联的元素节点解绑,防止用户在钩子里调用 findDOMNode方法
this.isMounted = returnFalse;
this._disposed = true;
vnode._disposed = this._disposed = true;
}
};
function transfer(queue) {
Expand Down Expand Up @@ -2762,7 +2774,9 @@ function unmountComponentAtNode(container) {
drainQueue(queue);
emptyElement(container);
container.__component = null;
return true;
}
return false;
}
//[Top API] ReactDOM.findDOMNode
function findDOMNode(componentOrElement) {
Expand Down Expand Up @@ -2913,8 +2927,7 @@ function updateVnode(lastVnode, nextVnode, context, updateQueue, insertCarrier)
var dom = nextVnode.stateNode = lastVnode.stateNode;
options.beforeUpdate(nextVnode);
if (lastVnode.vtype < 2) {
var insertPoint = insertCarrier.dom;
insertElement(nextVnode, insertPoint);
insertElement(nextVnode, insertCarrier.dom);
insertCarrier.dom = dom;
if (lastVnode.vtype === 0) {
if (nextVnode.text !== lastVnode.text) {
Expand Down Expand Up @@ -2973,7 +2986,9 @@ function receiveComponent(lastVnode, nextVnode, parentContext, updateQueue, inse
if (!updater._dirty) {
updater._receiving = true;
updater.updateQueue = updateQueue;
captureError(stateNode, "componentWillReceiveProps", [nextVnode.props, nextContext]);
if (willReceive) {
captureError(stateNode, "componentWillReceiveProps", [nextVnode.props, nextContext]);
}
if (updater._hasError) {
return;
}
Expand Down Expand Up @@ -3080,7 +3095,7 @@ if (win.React && win.React.options) {
React = win.React; //解决引入多个
} else {
React = win.React = win.ReactDOM = {
version: "2.0.2",
version: "2.0.3",
render: render,
hydrate: render,
options: options,
Expand Down
2 changes: 1 addition & 1 deletion dist/React.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9d12b3a

Please sign in to comment.