{"action":"created","issue":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/607","labels_url":"https://api.github.com/repos/lhorie/mithril.js/issues/607/labels{/name}","comments_url":"https://api.github.com/repos/lhorie/mithril.js/issues/607/comments","events_url":"https://api.github.com/repos/lhorie/mithril.js/issues/607/events","html_url":"https://github.com/lhorie/mithril.js/issues/607","id":73786507,"number":607,"title":"Way to retain a node/subtree between different positions in the DOM","user":{"login":"tobscure","id":128862,"avatar_url":"https://avatars.githubusercontent.com/u/128862?v=3","gravatar_id":"","url":"https://api.github.com/users/tobscure","html_url":"https://github.com/tobscure","followers_url":"https://api.github.com/users/tobscure/followers","following_url":"https://api.github.com/users/tobscure/following{/other_user}","gists_url":"https://api.github.com/users/tobscure/gists{/gist_id}","starred_url":"https://api.github.com/users/tobscure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobscure/subscriptions","organizations_url":"https://api.github.com/users/tobscure/orgs","repos_url":"https://api.github.com/users/tobscure/repos","events_url":"https://api.github.com/users/tobscure/events{/privacy}","received_events_url":"https://api.github.com/users/tobscure/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-07T00:47:04Z","updated_at":"2015-05-08T01:30:46Z","closed_at":null,"body":"Suppose on one page I have a Mithril DOM structure like this:\r\n\r\n```html\r\n<div class=\"level1\">\r\n  <div class=\"expensive\">expensive-to-draw subtree</div>\r\n</div>\r\n```\r\n\r\nThen on another page, I have a more complex DOM structure like this:\r\n```html\r\n<div class=\"level1\">\r\n  <div>something</div>\r\n  <div class=\"level2\">\r\n    <div>something else</div>\r\n    <div class=\"expensive\">expensive-to-draw subtree</div>\r\n  </div>\r\n</div>\r\n```\r\n\r\nIs there any way to retain div.expensive when redrawing between the two pages? I don't imagine that {subtree: \"retain\"} and context.retain will work in this scenario because the expensive div is in a completely different DOM position between the pages.\r\n\r\nAny ideas?"},"comment":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/comments/100063455","html_url":"https://github.com/lhorie/mithril.js/issues/607#issuecomment-100063455","issue_url":"https://api.github.com/repos/lhorie/mithril.js/issues/607","id":100063455,"user":{"login":"pelonpelon","id":254146,"avatar_url":"https://avatars.githubusercontent.com/u/254146?v=3","gravatar_id":"","url":"https://api.github.com/users/pelonpelon","html_url":"https://github.com/pelonpelon","followers_url":"https://api.github.com/users/pelonpelon/followers","following_url":"https://api.github.com/users/pelonpelon/following{/other_user}","gists_url":"https://api.github.com/users/pelonpelon/gists{/gist_id}","starred_url":"https://api.github.com/users/pelonpelon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pelonpelon/subscriptions","organizations_url":"https://api.github.com/users/pelonpelon/orgs","repos_url":"https://api.github.com/users/pelonpelon/repos","events_url":"https://api.github.com/users/pelonpelon/events{/privacy}","received_events_url":"https://api.github.com/users/pelonpelon/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T01:30:46Z","updated_at":"2015-05-08T01:30:46Z","body":"I've been thinking a lot about this. In my head I call it the ' globalKeyCache'. In a closed system it would just be an array, keeping order (for list maintenance) and telling the diff engine to trust when a key is matched. If matched, even in a different part of the vDOM, it would be 'retained'. With each render, unclaimed keys would be discarded -- functionally similar to the current key system but applicable to any element with a default of 'retain'. @tobscure I think this is what you're proposing. Finer grained control than subtree:retain, more general than the current key mechanism. It would be up to the dev to change keys (i.e. when data is potentially stale) -- with great power comes great responsibility!!. \r\n\r\nThe idea begs endless questions, but the first that comes to mind is the problem that @lhorie and @barneycarroll have been discussing WRT components: You'd have to namespace keys to avoid collisions/overwriting from outside components, plugins, and libraries, which is a hard problem."}}