const preact = require('preact'); const { connect } = require('preact-redux'); const addState = connect(({ vboxCombiner }) => ({ vboxCombiner })); class Combiner extends preact.Component { shouldComponentUpdate(newProps) { if (newProps.vbox !== this.props.vbox) return true; if (newProps.vboxSelected !== this.props.vboxSelected) return true; if (newProps.vboxBuySelected !== this.props.vboxBuySelected) return true; if (newProps.sendVboxCombine !== this.props.sendVboxCombine) return true; if (newProps.vboxCombiner !== this.props.vboxCombiner) return true; return false; } render(args) { const { // passed props vbox, vboxSelected, vboxBuySelected, sendVboxCombine, // state props vboxCombiner, } = args; const { stashSelect, storeSelect } = vboxSelected; function cost([group, i]) { if (group === 'Colours') return 1; if (group === 'Skills') return 2; if (group === 'Specs') return 3; }; if (vboxCombiner) { const combinerComboText = vboxCombiner.replace('Plus', '+'); let bits = 0; storeSelect.forEach(item => bits += cost(item)); return ( ); } if (stashSelect.length === 0 && storeSelect.length === 1) { const item = storeSelect[0]; return ( ); } return false; } } module.exports = addState(Combiner);