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 Switch = ({ on, onToggle }) => ( | |
| <label className={styles.switch} onClick={onToggle}> | |
| <input | |
| checked={on} | |
| type="checkbox" | |
| /> | |
| <span className={styles.slider} /> | |
| </label> | |
| ); |
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 mousePosition = () => (BaseComponent) => { | |
| return class MousePosition extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { x: 0, y: 0 }; | |
| } | |
| componentDidMount() { | |
| this.listener = (e) => { | |
| this.setState(() => ({ x: e.pageX, y: e.pageY })); |
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 tween = ({ tween, duration = 1000, defaultStart, end }) => (BaseComponent) => { | |
| return class Tween extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| timeStart: +new Date(), | |
| start: defaultStart(props) || 0, | |
| current: defaultStart(props) || 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
| import { compose, mapProps } from 'recompose'; | |
| const startX = 0; | |
| const startY = 0; | |
| const FollowingRectangle = compose( | |
| mousePosition(), | |
| tween({ | |
| tween: linear, | |
| duration: 1000, |
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 mousePosition = () => (BaseComponent) => { | |
| return class MousePosition extends Component { | |
| // ... | |
| render() { | |
| const { x, y } = this.state; | |
| return <BaseComponent {...this.props} x={x} y={y} />; | |
| } | |
| } |
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 tween = ({ tween, duration = 1000, defaultStart, end }) => (BaseComponent) => { | |
| return class Tween extends Component { | |
| // ... | |
| render() { | |
| const { current } = this.state; | |
| return <BaseComponent {...this.props} current={current} /> | |
| } | |
| } |
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
| function createMatrix(a = 1, b = a) { | |
| return Array.from({ length: a }, () => Array.from({ length: b }, () => 0)); | |
| } | |
| // 1 x 10 Matrix | |
| console.log(createMatrix(1, 10)); | |
| // Square Matrix | |
| console.log(createMatrix(3)); |
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
| Array.from(document.getElementsByTagName('div')); |
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
| function fillArray(length, value = 0) { | |
| return Array.from({ length }, () => value); | |
| } | |
| console.log(fillArray(10, 0)); // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
| console.log(fillArray(2, null)); // [null, 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
| function dedup(arr) { | |
| return Array.from(new Set(arr)); | |
| }; | |
| console.log(dedup([10, 10, 1, 0, 'a', 'b', 'a'])); |