{"action":"created","issue":{"url":"https://api.github.com/repos/mgechev/angular2-hot-loader/issues/10","labels_url":"https://api.github.com/repos/mgechev/angular2-hot-loader/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/mgechev/angular2-hot-loader/issues/10/comments","events_url":"https://api.github.com/repos/mgechev/angular2-hot-loader/issues/10/events","html_url":"https://github.com/mgechev/angular2-hot-loader/issues/10","id":123304158,"number":10,"title":"Hot reload a component's constructor","user":{"login":"frederikschubert","id":4137975,"avatar_url":"https://avatars.githubusercontent.com/u/4137975?v=3","gravatar_id":"","url":"https://api.github.com/users/frederikschubert","html_url":"https://github.com/frederikschubert","followers_url":"https://api.github.com/users/frederikschubert/followers","following_url":"https://api.github.com/users/frederikschubert/following{/other_user}","gists_url":"https://api.github.com/users/frederikschubert/gists{/gist_id}","starred_url":"https://api.github.com/users/frederikschubert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frederikschubert/subscriptions","organizations_url":"https://api.github.com/users/frederikschubert/orgs","repos_url":"https://api.github.com/users/frederikschubert/repos","events_url":"https://api.github.com/users/frederikschubert/events{/privacy}","received_events_url":"https://api.github.com/users/frederikschubert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-21T15:56:07Z","updated_at":"2016-01-11T19:20:52Z","closed_at":null,"body":"I suppose that this could be implemented using the following `clone` function in the `updatePrototype` method. This was taken from [here](https://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object).\r\n```javascript\r\nfunction clone(obj) {\r\n    var copy;\r\n\r\n    // Handle the 3 simple types, and null or undefined\r\n    if (null == obj || \"object\" != typeof obj) return obj;\r\n\r\n    // Handle Date\r\n    if (obj instanceof Date) {\r\n        copy = new Date();\r\n        copy.setTime(obj.getTime());\r\n        return copy;\r\n    }\r\n\r\n    // Handle Array\r\n    if (obj instanceof Array) {\r\n        copy = [];\r\n        for (var i = 0, len = obj.length; i < len; i++) {\r\n            copy[i] = clone(obj[i]);\r\n        }\r\n        return copy;\r\n    }\r\n\r\n    // Handle Object\r\n    if (obj instanceof Object) {\r\n        copy = {};\r\n        for (var attr in obj) {\r\n            if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);\r\n        }\r\n        return copy;\r\n    }\r\n\r\n    throw new Error(\"Unable to copy obj! Its type isn't supported.\");\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/mgechev/angular2-hot-loader/issues/comments/170660606","html_url":"https://github.com/mgechev/angular2-hot-loader/issues/10#issuecomment-170660606","issue_url":"https://api.github.com/repos/mgechev/angular2-hot-loader/issues/10","id":170660606,"user":{"login":"frederikschubert","id":4137975,"avatar_url":"https://avatars.githubusercontent.com/u/4137975?v=3","gravatar_id":"","url":"https://api.github.com/users/frederikschubert","html_url":"https://github.com/frederikschubert","followers_url":"https://api.github.com/users/frederikschubert/followers","following_url":"https://api.github.com/users/frederikschubert/following{/other_user}","gists_url":"https://api.github.com/users/frederikschubert/gists{/gist_id}","starred_url":"https://api.github.com/users/frederikschubert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frederikschubert/subscriptions","organizations_url":"https://api.github.com/users/frederikschubert/orgs","repos_url":"https://api.github.com/users/frederikschubert/repos","events_url":"https://api.github.com/users/frederikschubert/events{/privacy}","received_events_url":"https://api.github.com/users/frederikschubert/received_events","type":"User","site_admin":false},"created_at":"2016-01-11T19:20:51Z","updated_at":"2016-01-11T19:20:51Z","body":"Using your approach should also enable us to hot-reload only those components that have changed, keeping the overall state of the application.\nIf we have a handle on the views containing the changed components it should be easy to destroy and reinstantiate them."}}