Skip to content

Instantly share code, notes, and snippets.

@hufeng
Last active May 12, 2019 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hufeng/2d89902972000b9e1cf9153e028383cd to your computer and use it in GitHub Desktop.
Save hufeng/2d89902972000b9e1cf9153e028383cd to your computer and use it in GitHub Desktop.
```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