Skip to content

Commit

Permalink
refactor(Cascader): Remove duplicate create loop function
Browse files Browse the repository at this point in the history
  • Loading branch information
myronliu347 committed Nov 15, 2018
1 parent 1349a4a commit 1600432
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/cascader/cascader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,22 @@ export default class Cascader extends Component {
}
}

updateCache(dataSource) {
this._v2n = {};
this._p2n = {};
const loop = (data, prefix = '0') => data.forEach((item, index) => {
setCache(data, prefix = '0') {
data.forEach((item, index) => {
const { value, children } = item;
const pos = `${prefix}-${index}`;
this._v2n[value] = this._p2n[pos] = { ...item, pos, _source: item };

if (children && children.length) {
loop(children, pos);
this.setCache(children, pos);
}
});
}

loop(dataSource);
updateCache(dataSource) {
this._v2n = {};
this._p2n = {};
this.setCache(dataSource);
}

normalizeValue(value) {
Expand Down

0 comments on commit 1600432

Please sign in to comment.