Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Map just shows as empty entity in devtools #64

Open
ekiep opened this issue Jun 8, 2017 · 1 comment
Open

Map just shows as empty entity in devtools #64

ekiep opened this issue Jun 8, 2017 · 1 comment

Comments

@ekiep
Copy link

ekiep commented Jun 8, 2017

Hello,
used the new Map in ngrx and try to debug it in the devtools for Chrome (58.0.3029.110) on macOS 10.12.5, but it shows as an empty entity. However test are not failing and when I print the Map it looks fine.

I ll add my State + initial state, maybe it helps understanding.

export interface State {
  myMap: Map<string, Item[]>;
}

const INITIAL_STATE: State = {
  myMap: new Map<string, Item[]>().set('default', []),
};
@juanlizarazo
Copy link

@ekiep

I run into this as well.

The new redux devtools extension from version v2.14.0 and up has support for { serialize: true }.
Unfortunately, @ngrx/store-devtools doesn't support that just yet. This allows serialization of Maps, Sets and more.

So, my work around in the meantime for nice development experience is to add the .toJSON method to the Map prototype which works great and I can see my Maps in state in redux dev tools.

if (environment.envName === 'dev') {
  (Map.prototype as any).toJSON = function () {
    return JSON.parse(JSON.stringify([...this]));
  };
}

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

No branches or pull requests

2 participants