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}
onClick={props.onClick}
disabled={props.disabled}
data-category={props['data-category']}
data-index={props['data-index']}
/>
<div class={scopedCss.labelContainer}>
<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 newCats = Object.keys(that.state.catToOrderedMods).reduce((acc, cat) => {
if (cat !== tCat) {
if (cat !== targetConf.category) {
acc[cat] = oldCats[cat];
} else {
acc[cat] = oldCats[cat].map(
(conf, index) => tIndex === index
(conf, index) => targetIndex === index
? Object.assign({}, conf, {value: !conf.value})
: conf
);
@ -103,7 +101,8 @@ export default function getMain(theState) {
const modsHandlers = {
onChange: linkEvent(this, this.handleModChange),
onClick: linkEvent(this, this.handleModCheck),
//onClick: linkEvent(this, this.handleModCheck),
onClick: (...args) => this.handleModCheck(this, ...args),
};
return createElement(TabPanel, {

View File

@ -11,7 +11,13 @@ export default function getModList(theState) {
<ol onChange={props.onChange}>
{
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]}
</InfoLi>)
)