{"action":"created","issue":{"url":"https://api.github.com/repos/mweststrate/immer/issues/202","repository_url":"https://api.github.com/repos/mweststrate/immer","labels_url":"https://api.github.com/repos/mweststrate/immer/issues/202/labels{/name}","comments_url":"https://api.github.com/repos/mweststrate/immer/issues/202/comments","events_url":"https://api.github.com/repos/mweststrate/immer/issues/202/events","html_url":"https://github.com/mweststrate/immer/issues/202","id":363036934,"node_id":"MDU6SXNzdWUzNjMwMzY5MzQ=","number":202,"title":"Idea: introduce limited support for immutable, cloneable classes","user":{"login":"mweststrate","id":1820292,"node_id":"MDQ6VXNlcjE4MjAyOTI=","avatar_url":"https://avatars0.githubusercontent.com/u/1820292?v=4","gravatar_id":"","url":"https://api.github.com/users/mweststrate","html_url":"https://github.com/mweststrate","followers_url":"https://api.github.com/users/mweststrate/followers","following_url":"https://api.github.com/users/mweststrate/following{/other_user}","gists_url":"https://api.github.com/users/mweststrate/gists{/gist_id}","starred_url":"https://api.github.com/users/mweststrate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mweststrate/subscriptions","organizations_url":"https://api.github.com/users/mweststrate/orgs","repos_url":"https://api.github.com/users/mweststrate/repos","events_url":"https://api.github.com/users/mweststrate/events{/privacy}","received_events_url":"https://api.github.com/users/mweststrate/received_events","type":"User","site_admin":false},"labels":[{"id":795239980,"node_id":"MDU6TGFiZWw3OTUyMzk5ODA=","url":"https://api.github.com/repos/mweststrate/immer/labels/proposal","name":"proposal","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-09-24T07:25:52Z","updated_at":"2018-12-22T23:56:45Z","closed_at":null,"author_association":"OWNER","body":"We could introduce limited support for classes, by preserving the `prototype` of an object when cloning objects. (See als the comments [here](https://github.com/mweststrate/immer/issues/155#issuecomment-423269290))\r\n\r\nThere are a few potential gotchas however\r\n* Not all data structures can safely be cloned by just preserving the prototype (e.g. most built-in types like, `Map`, `Buffer`, `HTMLElement` etc etc)\r\n  * So, cloneable classes should be marked specially, like `class X extends ImmerCloneable` or `X[immerCloneable] = true`\r\n* It becomes more unclear what kind of data structures can be cloned, and what not\r\n* `Object.create` needs [polyfilling?](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#Polyfill)"},"comment":{"url":"https://api.github.com/repos/mweststrate/immer/issues/comments/449604868","html_url":"https://github.com/mweststrate/immer/issues/202#issuecomment-449604868","issue_url":"https://api.github.com/repos/mweststrate/immer/issues/202","id":449604868,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTYwNDg2OA==","user":{"login":"aleclarson","id":1925840,"node_id":"MDQ6VXNlcjE5MjU4NDA=","avatar_url":"https://avatars2.githubusercontent.com/u/1925840?v=4","gravatar_id":"","url":"https://api.github.com/users/aleclarson","html_url":"https://github.com/aleclarson","followers_url":"https://api.github.com/users/aleclarson/followers","following_url":"https://api.github.com/users/aleclarson/following{/other_user}","gists_url":"https://api.github.com/users/aleclarson/gists{/gist_id}","starred_url":"https://api.github.com/users/aleclarson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aleclarson/subscriptions","organizations_url":"https://api.github.com/users/aleclarson/orgs","repos_url":"https://api.github.com/users/aleclarson/repos","events_url":"https://api.github.com/users/aleclarson/events{/privacy}","received_events_url":"https://api.github.com/users/aleclarson/received_events","type":"User","site_admin":false},"created_at":"2018-12-22T23:56:45Z","updated_at":"2018-12-22T23:56:45Z","author_association":"COLLABORATOR","body":"> Or even more common: binds a function in its constructor? (maybe even accidentally, by using x = () => {}). In that case, in the clone, the functions are bound to the original object, not to the clone. Imagine how hard that is to debug, your stepping into a function and suddenly you are working with an other object, but even in the debugger that is really hard to observe if you aren't actively looking for it!....\r\n\r\nThat's already off limits in Immer. You __cannot__ currently bind a method to its plain object and pass it into a `produce` function. And I mentioned this in my proposal."}}
{"actor":{"display_login":"aleclarson"}}