{"action":"created","issue":{"url":"https://api.github.com/repos/plotly/plotly.js/issues/2418","repository_url":"https://api.github.com/repos/plotly/plotly.js","labels_url":"https://api.github.com/repos/plotly/plotly.js/issues/2418/labels{/name}","comments_url":"https://api.github.com/repos/plotly/plotly.js/issues/2418/comments","events_url":"https://api.github.com/repos/plotly/plotly.js/issues/2418/events","html_url":"https://github.com/plotly/plotly.js/issues/2418","id":300877250,"number":2418,"title":"Immutable mode for nestedProperty","user":{"login":"vdh","id":573501,"avatar_url":"https://avatars2.githubusercontent.com/u/573501?v=4","gravatar_id":"","url":"https://api.github.com/users/vdh","html_url":"https://github.com/vdh","followers_url":"https://api.github.com/users/vdh/followers","following_url":"https://api.github.com/users/vdh/following{/other_user}","gists_url":"https://api.github.com/users/vdh/gists{/gist_id}","starred_url":"https://api.github.com/users/vdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vdh/subscriptions","organizations_url":"https://api.github.com/users/vdh/orgs","repos_url":"https://api.github.com/users/vdh/repos","events_url":"https://api.github.com/users/vdh/events{/privacy}","received_events_url":"https://api.github.com/users/vdh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-02-28T03:20:18Z","updated_at":"2018-03-07T03:19:43Z","closed_at":null,"author_association":"NONE","body":"Related to the immutable mode idea: #2389\r\n\r\nWhile exploring an immutable mode solution for [`react-plotly-js-editor`](https://github.com/plotly/react-plotly.js-editor), I noticed a dependency upon Plotly's `nestedProperty`.\r\n\r\nWhat would be the most ideal way to make an immutable alternative for `nestedProperty`?\r\n\r\nIn a generic scenario the dependency is:\r\n```js\r\nconst prop = nestedProperty(container, attr);\r\nprop.set(value); // container is mutated\r\n```\r\n\r\nAnd an alternative immutable API in `nestedProperty` could do this instead:\r\n```js\r\nconst prop = nestedProperty(container, attr);\r\nconst newContainer = prop.setImmutable(value);\r\n```\r\nWhere `setImmutable` is the same logic as `set` (`npSet`), but returns an updated copy of the container instead. Under the hood it would use something like [`immutability-helper`](https://github.com/kolodny/immutability-helper) to reuse unchanged data when copying.\r\n\r\nOr would it perhaps be better to create an alternative library file? For example:\r\n```js\r\nconst newContainer = nestedPropertySetImmutable(container, attr, value);\r\n```\r\nWhich would be an immutable conversion of `npSet` (using `immutability-helper`). The downside of this approach is that it might create a code fork between it and `nestedProperty`."},"comment":{"url":"https://api.github.com/repos/plotly/plotly.js/issues/comments/371009406","html_url":"https://github.com/plotly/plotly.js/issues/2418#issuecomment-371009406","issue_url":"https://api.github.com/repos/plotly/plotly.js/issues/2418","id":371009406,"user":{"login":"nicolaskruchten","id":203523,"avatar_url":"https://avatars1.githubusercontent.com/u/203523?v=4","gravatar_id":"","url":"https://api.github.com/users/nicolaskruchten","html_url":"https://github.com/nicolaskruchten","followers_url":"https://api.github.com/users/nicolaskruchten/followers","following_url":"https://api.github.com/users/nicolaskruchten/following{/other_user}","gists_url":"https://api.github.com/users/nicolaskruchten/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolaskruchten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolaskruchten/subscriptions","organizations_url":"https://api.github.com/users/nicolaskruchten/orgs","repos_url":"https://api.github.com/users/nicolaskruchten/repos","events_url":"https://api.github.com/users/nicolaskruchten/events{/privacy}","received_events_url":"https://api.github.com/users/nicolaskruchten/received_events","type":"User","site_admin":false},"created_at":"2018-03-07T03:19:43Z","updated_at":"2018-03-07T03:19:43Z","author_association":"MEMBER","body":"This is basically the same suggestion I've been making internally for a while, so I'm +1 for using `immutability-helper` or something like it here :) I'm about to start work on replacing uses of `nestedProperty` with `immutability-helper` over in the editor.\r\n\r\nThe concern I would have is more around situations where right now two disparate bits of plotly.js are essentially communicating using shared references, and this link being broken because one scope is writing to new objects while another scope is reading from a reference to an older, 'orphaned' object. How often does this sort of thing happen, @alexcjohnson ?"}}
{"actor":{"display_login":"nicolaskruchten"}}