{"action":"created","issue":{"url":"https://api.github.com/repos/Polymer/polymer/issues/1198","labels_url":"https://api.github.com/repos/Polymer/polymer/issues/1198/labels{/name}","comments_url":"https://api.github.com/repos/Polymer/polymer/issues/1198/comments","events_url":"https://api.github.com/repos/Polymer/polymer/issues/1198/events","html_url":"https://github.com/Polymer/polymer/issues/1198","id":57957067,"number":1198,"title":"Dynamically publishing attributes","user":{"login":"positlabs","id":1918844,"avatar_url":"https://avatars.githubusercontent.com/u/1918844?v=3","gravatar_id":"","url":"https://api.github.com/users/positlabs","html_url":"https://github.com/positlabs","followers_url":"https://api.github.com/users/positlabs/followers","following_url":"https://api.github.com/users/positlabs/following{/other_user}","gists_url":"https://api.github.com/users/positlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/positlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/positlabs/subscriptions","organizations_url":"https://api.github.com/users/positlabs/orgs","repos_url":"https://api.github.com/users/positlabs/repos","events_url":"https://api.github.com/users/positlabs/events{/privacy}","received_events_url":"https://api.github.com/users/positlabs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-02-17T17:48:01Z","updated_at":"2015-02-25T19:38:07Z","closed_at":null,"body":"It doesn't seem like there's a built-in way to dynamically publish attributes in Polymer components. I think there should be.\r\n\r\nI understand that publishing attributes during element registration is much more efficient. However, I'm writing a wrapper for a webgl lib where attributes are unknown until the elements are instantiated.\r\n\r\nHere is an example of what I'm trying to achieve:\r\n\r\n```html\r\n<seriously-graph linear>\r\n    <seriously-source>\r\n        <img src=\"images/pencils.jpg\">\r\n    </seriously-source>\r\n    <seriously-effect type=\"pixelate\" pixelSize=\"{{pixelSize}}\"></seriously-effect>\r\n    <seriously-effect type=\"blur\" amount=\".5\"></seriously-effect>\r\n    <seriously-target width=\"411\" height=\"425\"></seriously-target>\r\n</seriously-graph>\r\n```\r\n\r\nUnder the hood, this is what is happening in the effect nodes:\r\n\r\n```javascript\r\nvar effect = seriously.effect(this.type); // type is defined at runtime\r\nvar attributes = effect.inputs(); // these are the attributes this component instance cares about\r\n```\r\n\r\nIdeally I would just use a method from Polymer to dynamically publish attributes. Since I haven't found a way to do this, I have used MutationObserver to detect changes to attributes. This approach sort of works, but then I need to worry about serialization.\r\n\r\nHere is the project repository: \r\nhttps://github.com/positlabs/seriously.polymer\r\n\r\nAnd some SO questions I've created: \r\nhttp://stackoverflow.com/questions/28519217/dynamically-publish-attributes-in-polymer (check out that phat +50 bounty)\r\nhttp://stackoverflow.com/questions/28553399/serialize-unpublished-polymer-attributes"},"comment":{"url":"https://api.github.com/repos/Polymer/polymer/issues/comments/76038653","html_url":"https://github.com/Polymer/polymer/issues/1198#issuecomment-76038653","issue_url":"https://api.github.com/repos/Polymer/polymer/issues/1198","id":76038653,"user":{"login":"positlabs","id":1918844,"avatar_url":"https://avatars.githubusercontent.com/u/1918844?v=3","gravatar_id":"","url":"https://api.github.com/users/positlabs","html_url":"https://github.com/positlabs","followers_url":"https://api.github.com/users/positlabs/followers","following_url":"https://api.github.com/users/positlabs/following{/other_user}","gists_url":"https://api.github.com/users/positlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/positlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/positlabs/subscriptions","organizations_url":"https://api.github.com/users/positlabs/orgs","repos_url":"https://api.github.com/users/positlabs/repos","events_url":"https://api.github.com/users/positlabs/events{/privacy}","received_events_url":"https://api.github.com/users/positlabs/received_events","type":"User","site_admin":false},"created_at":"2015-02-25T19:38:07Z","updated_at":"2015-02-25T19:38:07Z","body":"@phestermcs \r\nIn the broken test, I get this error when trying to register more than one dynamic element. \r\n`Uncaught NotSupportedError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'seriously-effect-blur'. A type with that name is already registered.`\r\n\r\nAfter looking into why it was failing, I found that it was because I was appending `innerHTML` to `document.head` instead of creating a temp div, assigning `innerHTML`, and grabbing the `polymer-element` from there.\r\n\r\n```javascript\r\n// BAD. Somehow causes element declaration to register twice\r\nvar tmplString = '<polymer-element name=\"'+this.name+'\"></polymer-element>';\r\ndocument.head.innerHTML += tmplString;\r\n//document.body.innerHTML += tmplString; // also fails, and causes lifecycle callbacks to fire twice on the element generator\r\n\r\n//GOOD! Making a temporary, off-dom div and pulling the element out works.\r\nvar tmpDiv = document.createElement('div');\r\nvar tmplString = '<polymer-element name=\"'+this.name+'\"></polymer-element>';\r\ntmpDiv.innerHTML = tmplString;\r\ndocument.body.appendChild(tmpDiv.children[0]);\r\n```\r\n\r\nDo you think this is a bug in Polymer? I suppose I could make a test case with vanilla web components and compare results.\r\n\r\nI gave you the SO bounty. Thanks again for your help!\r\n\r\n@pflannery, good point. I plan to remove the publish object since it didn't do what I thought it would. I was trying to make it serialize objects by hinting at the type."}}