Replace data-attrs to arguments in data flow

This commit is contained in:
Ilya Ig. Petrov 2017-05-21 15:04:28 -07:00
parent adcab0ba97
commit 2581078ccf
3 changed files with 12 additions and 9 deletions

View File

@ -123,8 +123,6 @@ export default function getInfoLi() {
id={iddy} id={iddy}
onClick={props.onClick} onClick={props.onClick}
disabled={props.disabled} disabled={props.disabled}
data-category={props['data-category']}
data-index={props['data-index']}
/> />
<div class={scopedCss.labelContainer}> <div class={scopedCss.labelContainer}>
<label for={iddy} dangerouslySetInnerHTML={{__html: props.conf.label}}></label> <label for={iddy} dangerouslySetInnerHTML={{__html: props.conf.label}}></label>

View File

@ -62,18 +62,16 @@ export default function getMain(theState) {
} }
handleModCheck(that, event) { handleModCheck(that, {targetConf, targetIndex}) {
const checkbox = event.target;
const [tCat, tIndex] = [checkbox.dataset.category, parseInt(checkbox.dataset.index)];
const oldCats = that.state.catToOrderedMods; const oldCats = that.state.catToOrderedMods;
const newCats = Object.keys(that.state.catToOrderedMods).reduce((acc, cat) => { const newCats = Object.keys(that.state.catToOrderedMods).reduce((acc, cat) => {
if (cat !== tCat) { if (cat !== targetConf.category) {
acc[cat] = oldCats[cat]; acc[cat] = oldCats[cat];
} else { } else {
acc[cat] = oldCats[cat].map( acc[cat] = oldCats[cat].map(
(conf, index) => tIndex === index (conf, index) => targetIndex === index
? Object.assign({}, conf, {value: !conf.value}) ? Object.assign({}, conf, {value: !conf.value})
: conf : conf
); );
@ -103,7 +101,8 @@ export default function getMain(theState) {
const modsHandlers = { const modsHandlers = {
onChange: linkEvent(this, this.handleModChange), onChange: linkEvent(this, this.handleModChange),
onClick: linkEvent(this, this.handleModCheck), //onClick: linkEvent(this, this.handleModCheck),
onClick: (...args) => this.handleModCheck(this, ...args),
}; };
return createElement(TabPanel, { return createElement(TabPanel, {

View File

@ -11,7 +11,13 @@ export default function getModList(theState) {
<ol onChange={props.onChange}> <ol onChange={props.onChange}>
{ {
props.orderedConfigs.map((conf, index) => ( props.orderedConfigs.map((conf, index) => (
<InfoLi conf={conf} type='checkbox' checked={conf.value} key={index} data-category={conf.category} data-index={index} onClick={props.onClick}> <InfoLi
conf={conf}
type='checkbox'
checked={conf.value}
key={index}
onClick={() => props.onClick({targetConf: conf, targetIndex: index})}
>
{props.childrenOfMod && props.childrenOfMod[conf.key]} {props.childrenOfMod && props.childrenOfMod[conf.key]}
</InfoLi>) </InfoLi>)
) )