{"action":"closed","issue":{"url":"https://api.github.com/repos/esp/esp-js/issues/44","labels_url":"https://api.github.com/repos/esp/esp-js/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/esp/esp-js/issues/44/comments","events_url":"https://api.github.com/repos/esp/esp-js/issues/44/events","html_url":"https://github.com/esp/esp-js/issues/44","id":110504362,"number":44,"title":"Add support to observe events using decorators ","user":{"login":"KeithWoods","id":2853674,"avatar_url":"https://avatars.githubusercontent.com/u/2853674?v=3","gravatar_id":"","url":"https://api.github.com/users/KeithWoods","html_url":"https://github.com/KeithWoods","followers_url":"https://api.github.com/users/KeithWoods/followers","following_url":"https://api.github.com/users/KeithWoods/following{/other_user}","gists_url":"https://api.github.com/users/KeithWoods/gists{/gist_id}","starred_url":"https://api.github.com/users/KeithWoods/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KeithWoods/subscriptions","organizations_url":"https://api.github.com/users/KeithWoods/orgs","repos_url":"https://api.github.com/users/KeithWoods/repos","events_url":"https://api.github.com/users/KeithWoods/events{/privacy}","received_events_url":"https://api.github.com/users/KeithWoods/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-08T17:34:47Z","updated_at":"2015-10-08T17:35:23Z","closed_at":"2015-10-08T17:35:23Z","body":"You should be able to observe events using ES7 decorators.\r\n\r\nFor example the below class has several functions with decorators. The decorators specify the event name and optionally the observation stage. Calling `this._router.observeEventsOn(this._id, this)` (or `this._router.observeEventsOn(this)` for `SingleModelRouter`s) would wire up the event subscriptions and return a single disposable for the lot. Disposing this cancels the subscriptions. \r\n\r\n```js\r\nclass Model extends esp.model.DisposableBase {\r\n\tconstructor(id, router) {\r\n\t\tsuper();\r\n\t\tthis._id = id;\r\n\t\tthis._router = router;\r\n\t}\r\n\tobserveEvents() {\r\n\t\tthis.addDisposable(this._router.observeEventsOn(this._id, this));\r\n\t}\r\n\t@esp.observeEvent('fooEvent', esp.ObservationStage.preview)\r\n\t_observeFooEventAtPreview(e, c, m) {\r\n\t\tpreviewInvokeCount++;\r\n\t}\r\n\t@esp.observeEvent('fooEvent', esp.ObservationStage.normal)\r\n\t_observeFooEventAtNormal1(e, c, m) {\r\n\t\tnormalInvokeCount++;\r\n\t\tc.commit();\r\n\t}\r\n\t@esp.observeEvent('fooEvent')\r\n\t_observeFooEventAtNormal2(e, c, m) {\r\n\t\tnormal2InvokeCount++;\r\n\t}\r\n\t@esp.observeEvent('fooEvent', esp.ObservationStage.committed)\r\n\t_observeFooEventAtCommitted(e, c, m) {\r\n\t\tcommittedInvokeCount++;\r\n\t}\r\n}\r\n```"}}