-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
34 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,4 @@ | ||
import { batch2hd, isArray } from './src/util'; | ||
import jsx from './src/jsx'; | ||
import Fragment from './src/fragment'; | ||
|
||
// 实现jsx-runtime 入口,需要使用es5语法 | ||
var jsx = function(type: string | Function, props: any, key?: string) { | ||
// f2组件,需要再外部实例化 | ||
// @ts-ignore | ||
if (type.prototype && type.prototype.isComponent) { | ||
return { | ||
type, | ||
props, | ||
}; | ||
} | ||
if (typeof type === 'function') { | ||
return type(props); | ||
} | ||
const { style, attrs, children } = props; | ||
|
||
return { | ||
type, | ||
props, | ||
style: batch2hd(style) || {}, | ||
attrs: batch2hd(attrs), | ||
children: children && !isArray(children) ? [ children ] : children, | ||
key, | ||
}; | ||
}; | ||
|
||
export { Fragment, jsx, jsx as jsxs }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { batch2hd, isArray, isFunction } from './util'; | ||
|
||
// 实现jsx-runtime 入口 | ||
export default function(type: string | Function, props: any, key?: string) { | ||
if (isFunction(type)) { | ||
// f2组件,需要在外部实例化 | ||
// @ts-ignore | ||
if (type.prototype && type.prototype.isComponent) { | ||
return { | ||
type, | ||
props, | ||
key, | ||
}; | ||
} | ||
// @ts-ignore | ||
return type(props); | ||
} | ||
const { style, attrs, children } = props; | ||
|
||
return { | ||
type, | ||
props, | ||
style: batch2hd(style) || {}, | ||
attrs: batch2hd(attrs), | ||
children: children && !isArray(children) ? [ children ] : children, | ||
key, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters