kboom
kboom

Reputation: 2339

Why arrays in Immutable.js records are mutable?

I noticed that in the following piece of code

const TaskRecord = new Immutable.Record({
  name: '',
  requiredFor: [],
});

class Task extends TaskRecord {
}

const task = new Task();

task.requiredFor is really an array (calling get('requiredFor') inside the Task class yields the same result) and doesn't get converted to Immutable.List... this way the record isn't immutable.

Why it is this way? How to fix this?

Upvotes: 0

Views: 499

Answers (1)

kboom
kboom

Reputation: 2339

Seems like making magic in constructor does the job:

class Task extends TaskRecord {

   constructor(values) {
       super(Immutable.fromJS(values));
   }

}

Upvotes: 1

Related Questions