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]
不滿足我看來,我不恰當地使用不可變列表的方法。