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
module.exports = function ({ types: t }) { | |
const genTypeExpression = (node) => { | |
return t.callExpression( | |
t.memberExpression(t.identifier("React"), t.identifier("createElement")), | |
[ | |
/^[A-Z]/.test(node.type[0]) | |
? t.identifier(node.type) | |
: t.stringLiteral(node.type), | |
t.objectExpression(node.args), | |
...node.children.map(genTypeExpression), |
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
module.exports = function ({ types: t }) { | |
const GrandmaVisitor = { | |
StringLiteral(path, state) { | |
if (path.node.value === "👵") { | |
const recipeRef = state.grandmasRecipes[path.node.loc.start.line]; | |
const recipeMatches = recipeRef && recipeRef.start > path.node.start; | |
if (recipeMatches) { | |
const recipe = recipeRef.value; | |
const domStruc = cookRecipe(recipe, state.grandmasReference); |
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
module.exports = function ({ types: t }) { | |
const GrandmaVisitorInitiator = { | |
Program(path) { | |
const commentLineTokens = path.parent.comments.filter( | |
(token) => token.type === "CommentLine" | |
); | |
const commentBlockTokens = path.parent.comments.filter( | |
(token) => token.type === "CommentBlock" | |
); |
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
module.exports = function () { | |
const SimpleVisitor = { | |
StringLiteral(path, state) { | |
if (path.node.value === "We'll never survive!") { | |
path.node.value = "Nonsense. You're only saying that because no one ever has."; | |
} | |
}, | |
}; | |
return { visitor: SimpleVisitor }; |
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
const SwitchWithSlide = animateSwitch(Switch, SlideOut); | |
const App = () => ( | |
<SwitchWithSlide> | |
<Route path="/a" component={PathA} /> | |
<Route path="/b" component={PathB} /> | |
</SwitchWithSlide> | |
); |
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
const App = () => ( | |
<Switch> | |
<Route path="/a" component={PathA} /> | |
<Route path="/b" component={PathB} /> | |
</Switch> | |
); |
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
const animateSwitch = (CustomSwitch, AnimatorComponent) => ({ | |
children, | |
}) => ( | |
<Route | |
render={({ location }) => ( | |
<AnimatorComponent uniqKey={location.pathname}> | |
<CustomSwitch location={location}>{children}</CustomSwitch> | |
</AnimatorComponent> | |
)} | |
/> |
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
render() { | |
return ( | |
<Route | |
render={({ location }) => ( | |
<SlideOut uniqKey={location.pathname}> | |
<Switch location={location}> | |
<Route path="/a" component={PathA} /> | |
<Route path="/b" component={PathB} /> | |
</Switch> | |
</SlideOut> |
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
swapChildren = () => { | |
this.setState({ | |
childPosition: Slider.FROM_RIGHT, | |
prevChild: null, | |
prevUniqId: null, | |
animationCallback: null | |
}); | |
} |
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
componentDidUpdate(prevProps, prevState) { | |
const prevUniqId = prevProps.uniqKey || prevProps.children.type; | |
const uniqId = this.props.uniqKey || this.props.children.type; | |
if (prevUniqId !== uniqId) { | |
this.setState({ | |
childPosition: Slider.TO_LEFT, | |
curChild: this.props.children, | |
curUniqId: uniqId, | |
prevChild: prevProps.children, |
NewerOlder