{"action":"created","issue":{"url":"https://api.github.com/repos/aurelia/framework/issues/99","labels_url":"https://api.github.com/repos/aurelia/framework/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/aurelia/framework/issues/99/comments","events_url":"https://api.github.com/repos/aurelia/framework/issues/99/events","html_url":"https://github.com/aurelia/framework/issues/99","id":72455509,"number":99,"title":"Feature Request: Global callback for views/viewmodels for each local callback","user":{"login":"delebash","id":2220160,"avatar_url":"https://avatars.githubusercontent.com/u/2220160?v=3","gravatar_id":"","url":"https://api.github.com/users/delebash","html_url":"https://github.com/delebash","followers_url":"https://api.github.com/users/delebash/followers","following_url":"https://api.github.com/users/delebash/following{/other_user}","gists_url":"https://api.github.com/users/delebash/gists{/gist_id}","starred_url":"https://api.github.com/users/delebash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delebash/subscriptions","organizations_url":"https://api.github.com/users/delebash/orgs","repos_url":"https://api.github.com/users/delebash/repos","events_url":"https://api.github.com/users/delebash/events{/privacy}","received_events_url":"https://api.github.com/users/delebash/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-01T15:27:19Z","updated_at":"2015-05-01T16:08:28Z","closed_at":null,"body":"ie. a Global_attached() method that corresponds to attached() instance method\r\n\r\nSomething I am running into now is that I would like to be able to fire off some code each time a view is loaded.  I can use the attached method but if I want that same code to run on every class then I either have to copy the attached method to every class or extend each class with a base class that has the attached method defined.  Extending the class is ok, but still I have to touch each class by importing the base class and adding extends to it.\r\n\r\nInstead if we had a global method for each local method ie global_attached, global_canActivate, then it would be easy to define code one place maybe app.js for any local event.  If we pass the view instance to the global callback then we can also do something like if viewInstance.name starts with \"s\" then run code or if viewInstance.property=X run code, we can filter out views or apply it to all views.\r\n\r\nOne possible solution is to use inheritance and define a base class, but instead of  having to manually add that class, we could just have a property in the Aurelia config that says baseClass=\"myBaseClass.js\" and this gets applied to any class that the Router processes.  In this way not only do we make global's for Auriela's callbacks we also can add our own methods to the base class.  If we want to override the global_Attached method we just define attached for that class or we can also inherit and override by calling super.\r\n\r\nThere may be a better way to do this, as I am not a javascript expert by any means , but at least having global hooks that correspond to each local hook could be very useful.\r\n\r\nWhat do you all think?"},"comment":{"url":"https://api.github.com/repos/aurelia/framework/issues/comments/98167542","html_url":"https://github.com/aurelia/framework/issues/99#issuecomment-98167542","issue_url":"https://api.github.com/repos/aurelia/framework/issues/99","id":98167542,"user":{"login":"navels","id":2559156,"avatar_url":"https://avatars.githubusercontent.com/u/2559156?v=3","gravatar_id":"","url":"https://api.github.com/users/navels","html_url":"https://github.com/navels","followers_url":"https://api.github.com/users/navels/followers","following_url":"https://api.github.com/users/navels/following{/other_user}","gists_url":"https://api.github.com/users/navels/gists{/gist_id}","starred_url":"https://api.github.com/users/navels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navels/subscriptions","organizations_url":"https://api.github.com/users/navels/orgs","repos_url":"https://api.github.com/users/navels/repos","events_url":"https://api.github.com/users/navels/events{/privacy}","received_events_url":"https://api.github.com/users/navels/received_events","type":"User","site_admin":false},"created_at":"2015-05-01T16:08:28Z","updated_at":"2015-05-01T16:08:28Z","body":"Same kind of thing with our app built with Durandal.  We have some common AJAX requests that go in activate(), jquery init stuff in compositionComplete(), and some cleanup in deactivate().  We have a \"BasePage\" class that implements the lifecycle methods that the top-level views inherit from."}}