Last active
May 12, 2019 06:07
-
-
Save hufeng/2d89902972000b9e1cf9153e028383cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
```typescript | |
export const tpl = (strs: TemplateStringsArray, ...value: Array<Function>) => { | |
return (props: Object) => { | |
const merge = [] as Array<any>; | |
const params = value.map(v => v(props)); | |
const pLen = params.length; | |
const sLen = strs.length; | |
for (let i = 0; i < sLen; i++) { | |
merge.push(strs[i]); | |
if (i < pLen) { | |
merge.push(params[i]); | |
} | |
} | |
return merge.join(''); | |
}; | |
}; | |
``` | |
const t = tpl` | |
import React from 'react'; | |
const ${props => props.appName} = () => <Provider></Provider> | |
`; | |
console.log(t({appName: 'UserDetail'})) | |
//output | |
// | |
//import React from 'react'; | |
// | |
//const UserDetail = () => <Provider><Provider> | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment