Browse Source

新增h函数

es6
guy 4 years ago
parent
commit
e691b578d9
  1. 21
      src/core/h.js

21
src/core/h.js

@ -2,6 +2,22 @@ BI.Fragment = function () {
}; };
BI.h = function (type, props, children) { BI.h = function (type, props, children) {
if (children != null) {
if (!BI.isArray(children)) {
children = [children];
}
} else {
children = [];
}
if (arguments.length > 3) {
for (var i = 3; i < arguments.length; i++) {
if (BI.isArray(arguments[i])) {
children = children.concat(arguments[i]);
} else {
children.push(arguments[i]);
}
}
}
if (type === BI.Fragment) { if (type === BI.Fragment) {
return children; return children;
} }
@ -10,11 +26,10 @@ BI.h = function (type, props, children) {
} }
if (type === "el") { if (type === "el") {
return BI.extend({ return BI.extend({
el: BI.isArray(children) ? children[0] : children el: children[0]
}, props); }, props);
} }
return BI.extend({ return BI.extend({
type: type, type: type,
items: BI.isArray(children) ? children : [children] }, children.length > 0 ? {items: children} : {}, props);
}, props);
}; };
Loading…
Cancel
Save