Skip to content

Commit

Permalink
Merge branch 'master' into better-jsx-refs
Browse files Browse the repository at this point in the history
  • Loading branch information
LUKE知る committed Oct 30, 2019
2 parents dca43c4 + 87b945b commit c9f5dcb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
16 changes: 11 additions & 5 deletions src/component.js
Expand Up @@ -25,12 +25,18 @@ export function Component(props, context) {
*/
Component.prototype.setState = function(update, callback) {
// only clone state when copying to nextState the first time.
let s =
(this._nextState !== this.state && this._nextState) ||
(this._nextState = assign({}, this.state));
let s;
if (this._nextState !== this.state) {
s = this._nextState;
} else {
s = this._nextState = assign({}, this.state);
}

if (typeof update == 'function') {
update = update(s, this.props);
}

// if update() mutates state in-place, skip the copy:
if (typeof update !== 'function' || (update = update(s, this.props))) {
if (update) {
assign(s, update);
}

Expand Down
8 changes: 5 additions & 3 deletions src/diff/index.js
Expand Up @@ -85,10 +85,12 @@ export function diff(
c._nextState = c.state;
}
if (newType.getDerivedStateFromProps != null) {
if (c._nextState == c.state) {
c._nextState = assign({}, c._nextState);
}

assign(
c._nextState == c.state
? (c._nextState = assign({}, c._nextState))
: c._nextState,
c._nextState,
newType.getDerivedStateFromProps(newProps, c._nextState)
);
}
Expand Down
28 changes: 15 additions & 13 deletions src/diff/props.js
Expand Up @@ -34,13 +34,15 @@ export function diffProps(dom, newProps, oldProps, isSvg, hydrate) {
function setStyle(style, key, value) {
if (key[0] === '-') {
style.setProperty(key, value);
} else if (
typeof value === 'number' &&
IS_NON_DIMENSIONAL.test(key) === false
) {
style[key] = value + 'px';
} else if (value == null) {
style[key] = '';
} else {
style[key] =
typeof value === 'number' && IS_NON_DIMENSIONAL.test(key) === false
? value + 'px'
: value == null
? ''
: value;
style[key] = value;
}
}

Expand All @@ -53,13 +55,13 @@ function setStyle(style, key, value) {
* @param {boolean} isSvg Whether or not this DOM node is an SVG node or not
*/
function setProperty(dom, name, value, oldValue, isSvg) {
name = isSvg
? name === 'className'
? 'class'
: name
: name === 'class'
? 'className'
: name;
if (isSvg) {
if (name === 'className') {
name = 'class';
}
} else if (name === 'class') {
name = 'className';
}

if (name === 'key' || name === 'children') {
} else if (name === 'style') {
Expand Down

0 comments on commit c9f5dcb

Please sign in to comment.