Skip to content

Commit

Permalink
feat: 添加classic模式的jsx转换
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Jan 19, 2021
1 parent 6aac09a commit 2edbc00
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/fund-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export { default as WeaverLine } from './weaverLine';


export { default as Line } from './line';
export { default as Guide } from './guide';
export { default as Guide, withGuide, guideView } from './guide';
export { default as Axis } from './axis';
2 changes: 1 addition & 1 deletion packages/jsx/jsx-runtime.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"use strict";
module.exports = require('./lib/index.js');
module.exports = require('./lib/jsx-runtime.js');
7 changes: 2 additions & 5 deletions packages/jsx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import render from './render';
import jsx from './jsx';
import Fragment from './fragment';
import jsx from './jsx-classic';

export {
render,
Fragment,
jsx,
jsx as jsxs
};
};
File renamed without changes.
31 changes: 31 additions & 0 deletions packages/jsx/src/jsx-classic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { batch2hd, extendArray, isFunction } from './util';

// 实现jsx-classic 入口
export default function(type: string | Function, props: any, ...children: any[]) {
props = props || {};
if (isFunction(type)) {
// f2组件,需要在外部实例化
// @ts-ignore
if (type.prototype && type.prototype.isF2Component) {
return {
type,
props,
key: props.key,
};
}
// 如果是方法,直接执行,生成G的定义树
// @ts-ignore
return type(props);
}

const { style, attrs, key } = props;

return {
type,
props,
key,
style: batch2hd(style) || {},
attrs: batch2hd(attrs),
children: extendArray(children),
};
};
8 changes: 8 additions & 0 deletions packages/jsx/src/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import jsx from './jsx-automatic';
import Fragment from './fragment';

export {
Fragment,
jsx,
jsx as jsxs
};

0 comments on commit 2edbc00

Please sign in to comment.