add shouldComponentUpdate to vbox components
This commit is contained in:
parent
200482dd79
commit
c534f973a1
@ -2,14 +2,13 @@ const preact = require('preact');
|
|||||||
const range = require('lodash/range');
|
const range = require('lodash/range');
|
||||||
const reactStringReplace = require('react-string-replace');
|
const reactStringReplace = require('react-string-replace');
|
||||||
|
|
||||||
const { Component } = require('preact');
|
|
||||||
const { INFO } = require('./../constants');
|
const { INFO } = require('./../constants');
|
||||||
const { convertItem, removeTier } = require('../utils');
|
const { convertItem, removeTier } = require('../utils');
|
||||||
const { tutorialStage } = require('../tutorial.utils');
|
const { tutorialStage } = require('../tutorial.utils');
|
||||||
const shapes = require('./shapes');
|
const shapes = require('./shapes');
|
||||||
|
|
||||||
|
|
||||||
class InfoComponent extends Component {
|
class InfoComponent extends preact.Component {
|
||||||
shouldComponentUpdate(newProps) {
|
shouldComponentUpdate(newProps) {
|
||||||
if (newProps.tutorial !== this.props.tutorial) return true;
|
if (newProps.tutorial !== this.props.tutorial) return true;
|
||||||
if (newProps.tutorial) return false; // We don't care about info during tutorial
|
if (newProps.tutorial) return false; // We don't care about info during tutorial
|
||||||
|
|||||||
@ -18,7 +18,6 @@ const addState = connect(
|
|||||||
account,
|
account,
|
||||||
itemInfo,
|
itemInfo,
|
||||||
itemEquip,
|
itemEquip,
|
||||||
activeConstruct,
|
|
||||||
navInstance,
|
navInstance,
|
||||||
tutorial,
|
tutorial,
|
||||||
} = state;
|
} = state;
|
||||||
@ -39,7 +38,6 @@ const addState = connect(
|
|||||||
itemInfo,
|
itemInfo,
|
||||||
itemEquip,
|
itemEquip,
|
||||||
navInstance,
|
navInstance,
|
||||||
activeConstruct,
|
|
||||||
sendUnequip,
|
sendUnequip,
|
||||||
tutorial,
|
tutorial,
|
||||||
};
|
};
|
||||||
@ -77,19 +75,21 @@ const addState = connect(
|
|||||||
|
|
||||||
function Construct(props) {
|
function Construct(props) {
|
||||||
const {
|
const {
|
||||||
|
// Changing state variables
|
||||||
|
construct,
|
||||||
iter,
|
iter,
|
||||||
itemEquip,
|
itemEquip,
|
||||||
construct,
|
itemInfo,
|
||||||
|
mobileVisible,
|
||||||
player,
|
player,
|
||||||
|
tutorial,
|
||||||
|
// Function Calls
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
|
sendUnequip,
|
||||||
setActiveConstruct,
|
setActiveConstruct,
|
||||||
setItemUnequip,
|
setItemUnequip,
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
itemInfo,
|
|
||||||
setInfo,
|
setInfo,
|
||||||
sendUnequip,
|
|
||||||
mobileVisible,
|
|
||||||
tutorial,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const { vbox } = player;
|
const { vbox } = player;
|
||||||
@ -242,25 +242,37 @@ function Construct(props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function InstanceConstructs(props) {
|
class InstanceConstructs extends preact.Component {
|
||||||
|
shouldComponentUpdate(newProps) {
|
||||||
|
if (newProps.itemEquip !== this.props.itemEquip) return true;
|
||||||
|
if (newProps.instance.phase !== this.props.instance.phase) return true;
|
||||||
|
if (newProps.tutorial !== this.props.tutorial) return true;
|
||||||
|
if (newProps.navInstance !== this.props.navInstance) return true;
|
||||||
|
// JSON or Array objects
|
||||||
|
if (JSON.stringify(newProps.player) !== JSON.stringify(this.props.player)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
render(props) {
|
||||||
const {
|
const {
|
||||||
activeConstruct,
|
// Changing state variables
|
||||||
itemEquip,
|
itemEquip,
|
||||||
|
instance, // we only change phase
|
||||||
|
navInstance,
|
||||||
player,
|
player,
|
||||||
instance,
|
tutorial,
|
||||||
// clearInfo,
|
// Static data
|
||||||
|
itemInfo,
|
||||||
|
// Function calls
|
||||||
setInfo,
|
setInfo,
|
||||||
setActiveConstruct,
|
setActiveConstruct,
|
||||||
|
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
itemInfo,
|
|
||||||
setVboxHighlight,
|
setVboxHighlight,
|
||||||
setItemUnequip,
|
setItemUnequip,
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
sendUnequip,
|
sendUnequip,
|
||||||
navInstance,
|
|
||||||
tutorial,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
console.log('grep constructs');
|
||||||
|
|
||||||
if (!player) return false;
|
if (!player) return false;
|
||||||
if (instance.phase === 'Lobby') return false;
|
if (instance.phase === 'Lobby') return false;
|
||||||
@ -276,7 +288,6 @@ function InstanceConstructs(props) {
|
|||||||
return Construct({
|
return Construct({
|
||||||
iter: i,
|
iter: i,
|
||||||
construct: player.constructs[i],
|
construct: player.constructs[i],
|
||||||
activeConstruct,
|
|
||||||
itemEquip,
|
itemEquip,
|
||||||
setItemUnequip,
|
setItemUnequip,
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
@ -298,5 +309,6 @@ function InstanceConstructs(props) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = addState(InstanceConstructs);
|
module.exports = addState(InstanceConstructs);
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
const preact = require('preact');
|
const preact = require('preact');
|
||||||
|
const { connect } = require('preact-redux');
|
||||||
const range = require('lodash/range');
|
const range = require('lodash/range');
|
||||||
const countBy = require('lodash/countBy');
|
const countBy = require('lodash/countBy');
|
||||||
const without = require('lodash/without');
|
const without = require('lodash/without');
|
||||||
const { connect } = require('preact-redux');
|
|
||||||
const { removeTier } = require('../utils');
|
const { removeTier } = require('../utils');
|
||||||
const shapes = require('./shapes');
|
const shapes = require('./shapes');
|
||||||
const actions = require('../actions');
|
const actions = require('../actions');
|
||||||
@ -95,31 +96,47 @@ const addState = connect(
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
function Vbox(args) {
|
class Vbox extends preact.Component {
|
||||||
|
shouldComponentUpdate(newProps) {
|
||||||
|
// Single variable props
|
||||||
|
if (newProps.combiner !== this.props.combiner) return true;
|
||||||
|
if (newProps.itemUnequip !== this.props.itemUnequip) return true;
|
||||||
|
if (newProps.reclaiming !== this.props.reclaiming) return true;
|
||||||
|
if (newProps.navInstance !== this.props.navInstance) return true;
|
||||||
|
if (newProps.tutorial !== this.props.tutorial) return true;
|
||||||
|
// Don't bother if info changes during tutorial
|
||||||
|
if (!newProps.tutorial && newProps.info !== this.props.info) return true;
|
||||||
|
// JSON or Array objects
|
||||||
|
if (JSON.stringify(newProps.vboxSelected) !== JSON.stringify(this.props.vboxSelected)) return true;
|
||||||
|
if (JSON.stringify(newProps.player) !== JSON.stringify(this.props.player)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
render(args) {
|
||||||
const {
|
const {
|
||||||
|
// Changing state variables
|
||||||
combiner,
|
combiner,
|
||||||
navInstance,
|
itemUnequip,
|
||||||
itemInfo,
|
|
||||||
player,
|
player,
|
||||||
reclaiming,
|
reclaiming,
|
||||||
|
tutorial,
|
||||||
|
navInstance,
|
||||||
|
info,
|
||||||
|
vboxSelected,
|
||||||
|
|
||||||
|
// Static
|
||||||
|
itemInfo,
|
||||||
|
// Function Calls
|
||||||
|
sendItemUnequip,
|
||||||
sendVboxAccept,
|
sendVboxAccept,
|
||||||
sendVboxCombine,
|
sendVboxCombine,
|
||||||
sendVboxDiscard,
|
sendVboxDiscard,
|
||||||
sendVboxReclaim,
|
sendVboxReclaim,
|
||||||
|
|
||||||
setCombiner,
|
|
||||||
setInfo,
|
|
||||||
|
|
||||||
vboxSelected,
|
|
||||||
setVboxSelected,
|
setVboxSelected,
|
||||||
|
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
tutorial,
|
setInfo,
|
||||||
itemUnequip,
|
setCombiner,
|
||||||
sendItemUnequip,
|
|
||||||
|
|
||||||
setReclaiming,
|
setReclaiming,
|
||||||
info,
|
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
if (!player) return false;
|
if (!player) return false;
|
||||||
@ -423,5 +440,6 @@ function Vbox(args) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = addState(Vbox);
|
module.exports = addState(Vbox);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user