2
我试图使用Immutable.js列出方法打字稿功能转化为Immutable.js打字稿列表
在我的课,我有
public checkVisible:any = [];
public rowChecked(index){
if (this.checkVisible.indexOf(index) === -1) {
this.checkVisible.push(index);
}
else {
this.checkVisible.splice(this.checkVisible.indexOf(index), 1);
console.log(this.checkVisible);
}
}
尝试转换到本我的功能转换为新功能:
public checkVisible:Immutable.List<any> = Immutable.List([]);
public rowChecked(index){
if (this.checkVisible.indexOf(index) === -1) {
this.checkVisible = this.checkVisible.push(index);
}
else {
this.checkVisible = this.checkVisible.delete(index);
console.log(this.checkVisible, 'REMOVED');
}
}
第一函数的工作需要:
this.rowChecked(0);
this.rowChecked(2);
this.rowChecked(2);
this.rowChecked now is Array[1] = [0:0]
但不可变列表功能做到这一点:
this.rowChecked(0);
this.rowChecked(2);
this.rowChecked(2);
this.rowChecked now is Array[2] = [0:0, 1:2]
不满足我看来,我不恰当地使用不可变列表的方法。