const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { TIMES, COLOURS } = require('../../constants'); class Strike extends Component { constructor() { super(); this.animations = []; } render() { return ( ); } componentDidMount() { this.animations.push(anime({ targets: ['#strike rect'], easing: 'easeOutExpo', y: [800, 100, 100], x: [200, 0, 200], height: [200, 10, 0], width: [20, 400, 0], duration: TIMES.TARGET_DURATION_MS, delay: TIMES.TARGET_DURATION_MS * 0.2, })); this.animations.push(anime({ targets: ['#strikeFilter feTurbulence', '#strikeFilter feDisplacementMap'], baseFrequency: 2, scale: 50, numOctaves: 5, easing: 'easeOutSine', delay: TIMES.TARGET_DURATION_MS / 3, duration: TIMES.TARGET_DURATION_MS / 2, })); } // this is necessary because // skipping / timing / unmounting race conditions // can cause the animations to cut short, this will ensure the values are reset // because preact will recycle all these components componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } } } module.exports = Strike;