Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Map mutates Records #268

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

Closed
zgotsch opened this issue Dec 29, 2014 · 2 comments
Closed

Map mutates Records #268

zgotsch opened this issue Dec 29, 2014 · 2 comments

Comments

@zgotsch
Copy link

zgotsch commented Dec 29, 2014

I noticed when using Records that using map mutates the record and returns undefined. I assumed that map would return a new record and leave the old record unmodified.

var Immutable = require("immutable");

var Person = Immutable.Record({name: "Zach", age: 25});

var me = new Person();
console.log(me.toString());
// Record { name: "Zach", age: 25 }

me.map(function(v, k) {
  if (k === "age") {
    return v + 1;
  } else {
    return v;
  }
});  // -> undefined

console.log(me.toString());
// Record { name: "Zach", age: 26 }
@andreypopp
Copy link

Similar to #220, probably.

@zgotsch
Copy link
Author

zgotsch commented Dec 30, 2014

Yeah, I noticed that filter also had weird behaviour. I expected map to work because I think of records as similar to Map<string, any>, but maybe that's the wrong way to think about them, especially since something like filter would have to reinstate the defaults for filtered fields if it returns the record type, or return a different type altogether (Map).

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

3 participants