Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using dot-notation to access Immutable.js Records

I read here that is possible to access a prop of a Record object using dot-notation like person.Name X person.get('name'). However it isn't working to me if I try to access it using the property directly.

My code:

new Record({
  id: 123,
  description: 'Foo',
  imgSrc: 'https://foo.co'
}))

If I try to access the property description directly like person.description it doesn't work. I should use person.get('description') rather access it directly.

What I'm doing wrong since it should let me access the property directly?

like image 592
Dan Avatar asked Jul 26 '26 03:07

Dan


1 Answers

You're a using a Map, but property access using dot notation is only available on Immutable.Record. Here's the relevant section on the site: https://facebook.github.io/immutable-js/docs/#/Record

//first make a template
var MyThingie = Record({id:123, description:'Foo', imgSrc: 'https://foo.co'});
//now create records
var myRecord = new MyThingie({description:'Not the default description'});
//outputs 'Not the default description'
console.log(myRecord.description);
like image 182
lakemalcom Avatar answered Jul 30 '26 09:07

lakemalcom