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

iassign does not work correctly with ES6 Map #12

Closed
martinbu opened this issue Jun 1, 2017 · 2 comments
Closed

iassign does not work correctly with ES6 Map #12

martinbu opened this issue Jun 1, 2017 · 2 comments

Comments

@martinbu
Copy link

martinbu commented Jun 1, 2017

Hi, thanks for this great helper library.

Does this library support ES6 Map? For me the following example does not work correctly. 'm' is always empty in the setProp and therefore map3 (or mapX) contains always one element after adding further elements.

import * as iassign from 'immutable-assign';

iassign.setOption({useConstructor: true});

let map1 = new Map();

  let map2 = iassign(
    map1,
    m => {
      m.set(0, 'first'); return m;
    }
  );

  let map3 = iassign(
    map2,
    m => { m.set(1, 'second'); return m; }
  );

  console.log(map1.size) // size: 0
  console.log(map2.size) // size: 1
  console.log(map3.size) // size: 1

Additionally, I have to set the useConstructor Option in every file (after import), that the option is applied correctly.

@engineforce
Copy link
Owner

engineforce commented Jun 22, 2017

ES6 Map support is added in 1.0.36, please refer to example 9.

Note: even with the fix, getProp() won't be able to handle navigate into the map object, it only supports navigate upto the map object. E.g.,

// Works
// Assume copyFunc option is set

var nested1 = { a: { b: new Map() } };
nested1.a.b.set("c", { "d": 100 })

var nested2 = iassign(
    nested1,
    (m, ctx) => m.a.b,
    (b) => {
        b.set(0, 'first'); return b;
    }
);
// Will not work
// Assume copyFunc option is set

var nested1 = { a: { b: new Map() } };
nested1.a.b.set("c", { "d": 100 })

var nested2 = iassign(
    nested1,
    (m, ctx) => m.a.b.get("c"),
    (c) => {
        c.e = 200; 
        return c;
    }
);

@engineforce
Copy link
Owner

Regarding to set the useConstructor Option in every file (after import), can you create a git repo that can reproduce the bug?

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