const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { TIMES } = require('../../constants'); class Recharge extends Component { constructor() { super(); this.animations = []; } render() { return ( ); } componentDidMount() { this.animations.push(anime({ targets: ['#recharge'], opacity: [ { value: 1, delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.TARGET_FADE_IN_DURATION }, { value: 0, delay: TIMES.TARGET_FADE_OUT_DELAY, duration: TIMES.FADE_OUT_DURATION }, ], easing: 'easeInOutSine', })); this.animations.push(anime({ targets: ['#recharge path.white'], strokeWidth: [2, 1], easing: 'easeInOutSine', direction: 'alternate', delay: TIMES.TARGET_MAIN_DELAY, duration: TIMES.TARGET_MAIN_DURATION, })); this.animations.push(anime({ targets: ['#rechargeFilter feTurbulence', ' #rechargeFilter feDisplacementMap'], baseFrequency: 2, scale: 10, numOctaves: 5, easing: 'easeOutSine', delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.RESOLUTION_TOTAL_MS, })); } // 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 = Recharge;