Brandon Brandon - 1 month ago 21
Javascript Question

Do methods on Immutable.js Records replicate?

My app loads about 30-50 instances of an

Immutable.js Record
. I'd like to write a
getter
that applies a few operations to the data before returning it.

Is this efficient? Or will I end up with 30-50 copies in-memory of any method I write?

eta:

This is my current pattern:

export const EntityRecord = Immutable.Record({
// key/values
})

class Entity extends EntityRecord {

getProp() {
return this.get('property')
}

}

Answer

It depends on the implementation. You could simply write a utility method

export function myRecordGetter(myRecord) {
   ... do your work here ....
   return thingYouComputed;
}

Then just import and call it. If you plan to "extend" the functionality of a record, it depends on how you do it.

Comments