Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more details about Records. #9

Open
nmn opened this issue Apr 8, 2015 · 1 comment
Open

Some more details about Records. #9

nmn opened this issue Apr 8, 2015 · 1 comment

Comments

@nmn
Copy link
Contributor

nmn commented Apr 8, 2015

First, I would like to confirm some assumptions about Records. I think they should be added to the .md file for more clarity.

  • records will work with subscripts the same way as objects do
const a = #{a: 1}
a.a === 1
a['a'] === 1
  • Object.assign will work for records as well.
const b = Object.assign(#{}, {a: 1}, {b: 2}, #{b: 3})
b === #{a: 1, b: 3}
  • Values in a record can still be functions and other non-value types.
  • The only way to convert a record to an Object would be to use Object.assign

Some questions:

  • Is there no way of adding or updating a key on a record? With objects you can just set a new value. That seems impossible with records, but potentially very useful.
  • Will other class methods on Object also work on records? Object.keys for example?
  • Object is javascript are currently ordered in all major implementations. Will records also be ordered maps in this way?
  • What is the value of keeping separate types for record and ImmutableMap? Perhaps it's a better idea to combine the two into a single type. It would be called ImmutableMap, but it would actually be an orderedMap, just like javascript Object is practice.
@ckknight
Copy link
Contributor

I'm not sure if Object.assign should work if a record is the first argument. If it's one of the rest arguments, absolutely, but since Object.assign is expected to mutate the first argument, it seems strange that it would work on an immutable record.

Object.assign(#{}, {a: 1, b: 2}, {c: 3}) // TypeError
Object.assign({}, #{a: 1, b: 2}, {c: 3}) //=> {a: 1, b: 2, c: 3}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants