-
-
Save astexplorer/a206145e34e9ec363df8c6cd5bd9de75 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
{ | |
"v": 2, | |
"parserID": "babylon7", | |
"toolID": "babelv7", | |
"settings": { | |
"babylon7": null | |
}, | |
"versions": { | |
"babylon7": "7.0.0", | |
"babelv7": "7.0.0" | |
} | |
} |
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
const insatiable = require('@tvui/insatiable'); | |
const Header = insatiable( | |
{ | |
textStyle: { | |
size: 30, | |
color: 'blue' | |
} | |
}, | |
({ text, color }) => { | |
return { | |
text, | |
textStyle: { | |
color | |
} | |
}; | |
} | |
); |
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
export default function (babel) { | |
const { types: t } = babel; | |
return { | |
visitor: { | |
CallExpression(path) { | |
if (path.get('callee.name').node !== 'insatiable') { | |
return; | |
} | |
const staticStyle = path.get('arguments.0'); | |
const calculateStyle = path.get('arguments.1'); | |
const props = path.get('arguments.1.params.0.properties').map(p => p.node).map((n) => n.key.name); | |
path.replaceWithSourceString(` | |
(function createStyledComponent() { | |
const staticStyle = ${staticStyle}; | |
const calculateStyle = ${calculateStyle}; | |
const Component = function(props) { | |
return React.createElement( | |
'widget', | |
{ | |
staticStyle: staticStyle, | |
style: calculateStyle(props) | |
}, | |
props.children | |
); | |
}; | |
const areEqual = function(prevProps, nextProps) { | |
return prevProps === nextProps || ${props.map((name) => `prevProps.${name} === nextProps.${name}`).join('&&')} | |
} | |
return React.memo(Component, areEqual); | |
}()) | |
`); | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment