Skip to content

Commit

Permalink
Merge cc431b2 into eea7acd
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Mar 4, 2019
2 parents eea7acd + cc431b2 commit bbc8ff7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -123,7 +123,7 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.5",
"lodash": "^4.17.10",
"microbundle": "^0.9.0",
"microbundle": "^0.10.1",
"mocha": "^5.2.0",
"npm-run-all": "^4.0.0",
"sinon": "^6.1.3",
Expand Down
3 changes: 2 additions & 1 deletion src/component.js
@@ -1,5 +1,6 @@
import { assign } from './util';
import { diff, commitRoot } from './diff/index';
import { Fragment } from './create-element';

/**
* Base Component class. Provides `setState()` and `forceUpdate()`, which
Expand Down Expand Up @@ -94,7 +95,7 @@ Component.prototype.forceUpdate = function(callback) {
* ancestor's `getChildContext()`
* @returns {import('./index').ComponentChildren | void}
*/
Component.prototype.render = function () {};
Component.prototype.render = Fragment;

/**
* The render queue
Expand Down
7 changes: 3 additions & 4 deletions src/create-element.js
@@ -1,4 +1,3 @@
import { EMPTY_OBJ } from './constants';
import options from './options';

/**
Expand All @@ -23,7 +22,7 @@ export function createElement(type, props, children) {

// "type" may be undefined during development. The check is needed so that
// we can display a nice error message with our debug helpers
if (type && type.defaultProps!=null) {
if (type!=null && type.defaultProps!=null) {
for (let i in type.defaultProps) {
if (props[i]===undefined) props[i] = type.defaultProps[i];
}
Expand Down Expand Up @@ -85,11 +84,11 @@ export /* istanbul ignore next */ function Fragment() { }
export function coerceToVNode(possibleVNode) {
if (possibleVNode == null || typeof possibleVNode === 'boolean') return null;
if (typeof possibleVNode === 'string' || typeof possibleVNode === 'number') {
return createVNode(null, EMPTY_OBJ, possibleVNode, null, null);
return createVNode(null, null, possibleVNode, null, null);
}

if (Array.isArray(possibleVNode)) {
return createVNode(Fragment, { children: possibleVNode }, null, null, null);
return createElement(Fragment, null, possibleVNode);
}

// Clone vnode if it has already been used. ceviche/#57
Expand Down
2 changes: 1 addition & 1 deletion src/diff/children.js
Expand Up @@ -143,7 +143,7 @@ function getVNodeChildren(vnode) {
* @param {Array<import('../internal').VNode | null>} [flattened] An flat array of children to modify
*/
export function toChildArray(children, flattened) {
if (flattened===undefined) flattened = [];
if (flattened == null) flattened = [];
if (children==null || typeof children === 'boolean') {}
else if (Array.isArray(children)) {
for (let i=0; i < children.length; i++) {
Expand Down
14 changes: 9 additions & 5 deletions src/diff/props.js
Expand Up @@ -31,6 +31,7 @@ export function diffProps(dom, newProps, oldProps, isSvg) {
* @param {boolean} isSvg Whether or not this DOM node is an SVG node or not
*/
function setProperty(dom, name, value, oldValue, isSvg) {
let v;
if (name==='class' || name==='className') name = isSvg ? 'class' : 'className';

if (name==='style') {
Expand All @@ -42,26 +43,29 @@ function setProperty(dom, name, value, oldValue, isSvg) {
*/
let s = dom.style;

if (typeof value==='string') return s.cssText = value;
if (typeof oldValue==='string') s.cssText = '';
if (typeof value==='string') {
s.cssText = value;
}
else {
if (typeof oldValue==='string') s.cssText = '';
// remove values not in the new list
for (let i in oldValue) {
if (value==null || !(i in value)) s.setProperty(i, '');
}
}

for (let i in value) {
let v = value[i];
v = value[i];
if (oldValue==null || v!==oldValue[i]) {
s.setProperty(i.replace(/-?(?=[A-Z])/g, '-'), typeof v==='number' && IS_NON_DIMENSIONAL.test(i)===false ? (v + 'px') : v);
}
}
}
else if (name==='dangerouslySetInnerHTML') {
// Avoid re-applying the same '__html' if it did not changed between re-render
if (value && oldValue && value.__html==oldValue.__html) return;
dom.innerHTML = value && value.__html || '';
if (!value || !oldValue || value.__html!=oldValue.__html) {
dom.innerHTML = value && value.__html || '';
}
}
// Benchmark for comparison: https://esbench.com/bench/574c954bdb965b9a00965ac6
else if (name[0]==='o' && name[1]==='n') {
Expand Down

0 comments on commit bbc8ff7

Please sign in to comment.