const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { connect } = require('preact-redux'); const { TIMES, COLOURS } = require('../../constants'); const addState = connect( function receiveState(state) { const { animCb } = state; return { animCb }; } ); class Hybrid extends Component { constructor() { super(); this.animations = []; } render() { return ( ); } componentDidMount() { this.animations.push(anime({ targets: ['#hybrid'], opacity: [ { value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.2 }, { value: 0, delay: TIMES.TARGET_DURATION_MS * 0.6, duration: TIMES.TARGET_DURATION_MS * 0.2 }, ], transform: { value: ['rotate(0)', 'rotate(360)'], delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS, direction: 'alternate', }, easing: 'easeInOutSine', })); this.animations.push(anime({ r: [10, anime.random(10, 30)], targets: ['#hybrid circle.green-one'], cx: [50, 250, 50, 250], delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS, easing: 'easeInOutSine', loop: true, })); this.animations.push(anime({ r: [10, anime.random(10, 30)], targets: ['#hybrid circle.green-two'], cy: [250, 50, 250, 50], delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS, easing: 'easeInOutSine', loop: true, })); this.animations.push(anime({ r: [10, anime.random(10, 30)], targets: ['#hybrid circle.bluewhite-one'], fill: [COLOURS.WHITE, COLOURS.BLUE], cy: [50, 250, 50, 250], delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS, easing: 'easeInOutSine', loop: true, })); this.animations.push(anime({ r: [10, anime.random(10, 30)], targets: ['#hybrid circle.bluewhite-two'], cx: [250, 50, 250, 50], fill: [COLOURS.WHITE, COLOURS.BLUE], delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS, easing: 'easeInOutSine', loop: true, })); } componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } this.props.animCb && this.props.animCb(); } } module.exports = addState(Hybrid);