{"action":"created","issue":{"url":"https://api.github.com/repos/AmpersandJS/ampersand-view/issues/102","labels_url":"https://api.github.com/repos/AmpersandJS/ampersand-view/issues/102/labels{/name}","comments_url":"https://api.github.com/repos/AmpersandJS/ampersand-view/issues/102/comments","events_url":"https://api.github.com/repos/AmpersandJS/ampersand-view/issues/102/events","html_url":"https://github.com/AmpersandJS/ampersand-view/issues/102","id":56203683,"number":102,"title":"View initialization, and viewoptions","user":{"login":"brunoscopelliti","id":3489757,"avatar_url":"https://avatars.githubusercontent.com/u/3489757?v=3","gravatar_id":"","url":"https://api.github.com/users/brunoscopelliti","html_url":"https://github.com/brunoscopelliti","followers_url":"https://api.github.com/users/brunoscopelliti/followers","following_url":"https://api.github.com/users/brunoscopelliti/following{/other_user}","gists_url":"https://api.github.com/users/brunoscopelliti/gists{/gist_id}","starred_url":"https://api.github.com/users/brunoscopelliti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brunoscopelliti/subscriptions","organizations_url":"https://api.github.com/users/brunoscopelliti/orgs","repos_url":"https://api.github.com/users/brunoscopelliti/repos","events_url":"https://api.github.com/users/brunoscopelliti/events{/privacy}","received_events_url":"https://api.github.com/users/brunoscopelliti/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/AmpersandJS/ampersand-view/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-02T07:18:38Z","updated_at":"2015-02-02T21:57:56Z","closed_at":null,"body":"Hi there,\r\n\r\nI would know if there is any particular reason behind the fact that in the ampersand-view constructor, the view option attributes are updated only after the  initialize method is called?\r\n\r\n```\r\nthis.on('change:el', this._handleElementChange, this);\r\n\r\n// ...\r\n\r\nthis.initialize.apply(this, arguments);\r\nthis.set(_.pick(attrs, viewOptions));\r\n```\r\n\r\nI think having the options set before the view is initialized is the preferred behaviour; otherwise the same code is run twice, without a real need.\r\n\r\nIn my particular case, I am extending ampersand-view, with a module that retrieve a template from server (or local storage when available)... I will release it open source when I will reach an adeguate test coverage.\r\n\r\nDuring the initialization i've to change the template (root element, ...) \r\n\r\nwhen `this.set(_.pick(attrs, viewOptions));` is called `attrs.el` still references the old container, the one that was replaced with the server response... and this causes the fact that the event listeners are delegated to the wrong element.\r\n\r\nI would suggest to change the order of:\r\n\r\n```\r\nthis.set(_.pick(attrs, viewOptions));\r\nthis.initialize.apply(this, arguments);\r\n```\r\n\r\nDo you see any problem? I would be happy to submit a pull request for this.\r\nThanks for your time :)\r\n"},"comment":{"url":"https://api.github.com/repos/AmpersandJS/ampersand-view/issues/comments/72546868","html_url":"https://github.com/AmpersandJS/ampersand-view/issues/102#issuecomment-72546868","issue_url":"https://api.github.com/repos/AmpersandJS/ampersand-view/issues/102","id":72546868,"user":{"login":"brunoscopelliti","id":3489757,"avatar_url":"https://avatars.githubusercontent.com/u/3489757?v=3","gravatar_id":"","url":"https://api.github.com/users/brunoscopelliti","html_url":"https://github.com/brunoscopelliti","followers_url":"https://api.github.com/users/brunoscopelliti/followers","following_url":"https://api.github.com/users/brunoscopelliti/following{/other_user}","gists_url":"https://api.github.com/users/brunoscopelliti/gists{/gist_id}","starred_url":"https://api.github.com/users/brunoscopelliti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brunoscopelliti/subscriptions","organizations_url":"https://api.github.com/users/brunoscopelliti/orgs","repos_url":"https://api.github.com/users/brunoscopelliti/repos","events_url":"https://api.github.com/users/brunoscopelliti/events{/privacy}","received_events_url":"https://api.github.com/users/brunoscopelliti/received_events","type":"User","site_admin":false},"created_at":"2015-02-02T21:57:56Z","updated_at":"2015-02-02T21:57:56Z","body":"I forked the repo, and made the \"fix\"...\r\nit passes all the tests...\r\n\r\nI hope this can be merged soon... \r\nif you need more info, i am available for further clarification.\r\n"}}