Skip to content

Instantly share code, notes, and snippets.

@stephencookdev
stephencookdev / webpack.config.js
Last active March 5, 2018 11:59
Example webpack config (pre SMP)
const ForceCaseSensitivityPlugin = require("force-case-sensitivity-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
module.exports = {
entry: {
app: ["./app.js"]
},
output: "./public",
module: {
rules: [
@stephencookdev
stephencookdev / webpack.config.js
Last active February 18, 2018 23:32
Example webpack config (post SMP)
const ForceCaseSensitivityPlugin = require("force-case-sensitivity-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");
const smp = new SpeedMeasurePlugin();
module.exports = smp.wrap({
entry: {
app: ["./app.js"]
},
@stephencookdev
stephencookdev / App.js
Created July 16, 2018 15:09
`SwitchWithSlide` example
import React from "react";
import { animateSwitch } from "./animateSwitch";
import { SlideOut } from "./SlideOut";
const SwitchWithSlide = animateSwitch(Switch, SlideOut);
export default () => (
<SwitchWithSlide>
<Route path="/a" component={PageA} />
<Route path="/b" component={PageB} />
@stephencookdev
stephencookdev / SwitchWithSlide-render.js
Created July 16, 2018 15:12
`SwitchWithSlide` example - render
render() {
const {
prevChild,
curChild,
childPosition,
animationCallback,
} = this.state;
return (
<Slider
@stephencookdev
stephencookdev / SwitchWithSlide-update.js
Created July 16, 2018 15:14
`SwitchWithSlide` example - update
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,
@stephencookdev
stephencookdev / SwitchWithSlide-swap.js
Created July 16, 2018 15:15
`SwitchWithSlide` example - swap
swapChildren = () => {
this.setState({
childPosition: Slider.FROM_RIGHT,
prevChild: null,
prevUniqId: null,
animationCallback: null
});
}
@stephencookdev
stephencookdev / SwitchWithSlide-naive.js
Created July 16, 2018 15:17
`SwitchWithSlide` example - naive usage
render() {
return (
<Route
render={({ location }) => (
<SlideOut uniqKey={location.pathname}>
<Switch location={location}>
<Route path="/a" component={PathA} />
<Route path="/b" component={PathB} />
</Switch>
</SlideOut>
@stephencookdev
stephencookdev / SwitchWithSlide-hoc.js
Created July 16, 2018 15:18
`SwitchWithSlide` example - hoc
const animateSwitch = (CustomSwitch, AnimatorComponent) => ({
children,
}) => (
<Route
render={({ location }) => (
<AnimatorComponent uniqKey={location.pathname}>
<CustomSwitch location={location}>{children}</CustomSwitch>
</AnimatorComponent>
)}
/>
@stephencookdev
stephencookdev / SwitchWithSlide-vanilla.js
Last active July 16, 2018 15:23
`SwitchWithSlide` example - vanilla
const App = () => (
<Switch>
<Route path="/a" component={PathA} />
<Route path="/b" component={PathB} />
</Switch>
);
@stephencookdev
stephencookdev / SwitchWithSlide-hoc-usage.js
Created July 16, 2018 15:22
`SwitchWithSlide` example - hoc usage
const SwitchWithSlide = animateSwitch(Switch, SlideOut);
const App = () => (
<SwitchWithSlide>
<Route path="/a" component={PathA} />
<Route path="/b" component={PathB} />
</SwitchWithSlide>
);