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 class TimesTableApp extends React.Component { | |
changeValue = valueName => value => { | |
if (isFunction(value)) { | |
this.setState({ [valueName]: value(this.state[valueName]) }); | |
else { | |
this.setState({ [valueName]: value }); | |
} | |
}; | |
... |
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 const TimesTableControls = () => { | |
const playTimer = useRef(null); | |
const { timesTable, setTimesTable } = useContext(TimesTableContext); | |
const pause = () => clearInterval(playTimer.current); | |
const play = () => { | |
playTimer.current = setInterval(() => { | |
setTimesTable(timesTable + 0.1); | |
}, 100); |
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 class TimesTableApp extends React.Component { | |
changeValue = valueName => value => { | |
this.setState({ [valueName]: value }); | |
}; | |
state = { | |
pointCount: 10, | |
timesTable: 2, | |
lineColor: '#000000', |
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 interface TimesTableContextProps { | |
pointCount: number; | |
timesTable: number; | |
lineColor: string; | |
setPointCount: value => void; | |
setTimesTable: value => void; | |
setLineColor: value => void; | |
} |
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 const TimesTable = props => { | |
... | |
useEffect(() => { | |
redraw(); | |
window.addEventListener('resize', redraw); | |
return () => window.removeEventListener('resize', redraw); | |
}, []); | |
... |
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 const TimesTable = props => { | |
const [, forceUpdate] = useState(null); | |
const redraw = () => { | |
const canvas = canvasRef.current; | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
forceUpdate(true); | |
}; |
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 const TimesTable = props => { | |
const canvasRef = useRef(null); | |
const redraw = () => { | |
const canvas = canvasRef.current; | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
}; | |
let viz; |
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 class TimesTable extends React.Component<{ timesTable, pointCount, lineColor }> { | |
canvasRef = React.createRef(); | |
redraw = () => { | |
this.canvasRef.current.height = window.innerHeight; | |
this.canvasRef.current.width = window.innerWidth; | |
this.forceUpdate(); | |
}; | |
componentDidMount() { |
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 class About extends React.Component { | |
contentRef = React.createRef(); | |
async animate(show) { | |
... | |
this.setState({ show }); | |
} | |
render() { | |
return this.state.show ? | |
<AboutContent ref={this.contentRef} /> : | |
null; |
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 class About extends React.Component { | |
... | |
contentRef = React.createRef(); | |
render() { | |
return <AboutContent ref={this.contentRef} />; | |
} | |
} |