Dire che ho classi Task
e TaskGroup
Come utilizzare Immesable JS con classi ES6 digitate?
class Task{
constructor(public text:string){}
}
class TaskGroup {
constructor(public title:string = "new task group", public tasks:Task[] = []){}
}
Poi nel mio angolare 2 servizio creerò un immutabile Elenco dei TaskGroups
@Injectable()
class TaskService {
taskGroups:Immutable.List<TaskGroup>;
constructor() {
this.taskGroups = Immutable.List<TaskGroup>([new TaskGroup("Coding tasks")]);
}
}
In questo modo solo taskGroups List è immutabile. Qualunque cosa ci sia dentro non lo è. Anche se faccio Immutable.fromJS(...)
anziché Immutable.List<Board>(...)
, gli oggetti nidificati sono semplici oggetti Javascript.
Immutabile JS non suppone di ereditarietà di classe (Inheriting from Immutable object with ES6 #562)
//can't do this!
class TaskGroup extends Immutable.Map<string, any>{
constructor(public title:string = "new task group", public tasks:Task[]){}
}
//it complained about the class not having methods like set, delete etc
Così come creare oggetti di classe immutabili?
Si potrebbe voler dare un'occhiata a questo [collegamento] (http://blog.scottlogic.com/2016/01/05/angular2-with-immutablejs.html);) – Kutyel
@Kutyel il wrapper è un bel concetto. Forse dovresti scriverlo come risposta e link all'articolo. –
fatto, grazie per il tuo suggerimento^_^ – Kutyel