Say I have classes Task
and TaskGroup
class Task{
constructor(public text:string){}
}
class TaskGroup {
constructor(public title:string = "new task group", public tasks:Task[] = []){}
}
Then in my Angular 2 service I will create an Immutable List of TaskGroups
@Injectable()
class TaskService {
taskGroups:Immutable.List<TaskGroup>;
constructor() {
this.taskGroups = Immutable.List<TaskGroup>([new TaskGroup("Coding tasks")]);
}
}
This way only taskGroups List is immutable. Whatever is inside it isn't. Even if I do Immutable.fromJS(...)
instead of Immutable.List<Board>(...)
the nested objects are plain ol' Javascript objects.
Immutable JS doesn't supposed class inheritance (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
So how to create Immutable class objects?