The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Immutable.Record() as data models

Immutable.Record() as data models

5:33
The Immutable.js Record() allows you to model your immutable data much like you would model data with native Javascript classes or objects. It differs from native classes because it cannot be mutated after it's creation and it *always* has a default value. It's an excellent construct in which to piece together your stores, be them Flux or some other storage implementation. Let's quickly create an Immutable Record().
Watch this lesson now
Avatar
egghead.io

The Immutable.js Record() allows you to model your immutable data much like you would model data with native Javascript classes or objects. It differs from native classes because it cannot be mutated after it's creation and it always has a default value. It's an excellent construct in which to piece together your stores, be them Flux or some other storage implementation. Let's quickly create an Immutable Record().

Avatar
Lee

Won't the id field be pre-computed, and identical for each new ABRecord instance?

It'd be nice for Immutable to accept a function that runs in the event that the key isn't supplied to the constructor, so this could be generated on the fly.

In reply to egghead.io
Avatar
J.S.

Hey Lee! You are right, it will be the same as evidenced in this JSBin: https://jsbin.com/hanitum/edit?js,console

It would be nice if it could accept a function to generate an ID, but for now creating a class factory is the only option. Maybe make a PR on GH? :)

In reply to Lee
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?