{"action":"created","issue":{"url":"https://api.github.com/repos/riot/riot/issues/1201","labels_url":"https://api.github.com/repos/riot/riot/issues/1201/labels{/name}","comments_url":"https://api.github.com/repos/riot/riot/issues/1201/comments","events_url":"https://api.github.com/repos/riot/riot/issues/1201/events","html_url":"https://github.com/riot/riot/issues/1201","id":105767290,"number":1201,"title":"Feature request: A callback function after trigger","user":{"login":"AndreasHeintze","id":2219544,"avatar_url":"https://avatars.githubusercontent.com/u/2219544?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasHeintze","html_url":"https://github.com/AndreasHeintze","followers_url":"https://api.github.com/users/AndreasHeintze/followers","following_url":"https://api.github.com/users/AndreasHeintze/following{/other_user}","gists_url":"https://api.github.com/users/AndreasHeintze/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasHeintze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasHeintze/subscriptions","organizations_url":"https://api.github.com/users/AndreasHeintze/orgs","repos_url":"https://api.github.com/users/AndreasHeintze/repos","events_url":"https://api.github.com/users/AndreasHeintze/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasHeintze/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/riot/riot/labels/feature%20request","name":"feature request","color":"5319e7"},{"url":"https://api.github.com/repos/riot/riot/labels/question","name":"question","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-09-10T09:21:56Z","updated_at":"2015-09-13T16:13:52Z","closed_at":null,"body":"Hi!\r\n\r\nSay I keep state of a riot component in an object called state. I change some vars in this object and trigger a custom \"update\" event on this object. I have multiple listeners that is listening for this event. In these listeners I want to know what has changed in this update, so I want to compare vars in the state object with the same vars in another object I named statePrev. Then I can see what has changed by making a diff of these two objects or by comparing some specific vars in these objects. Then when all listeners has executed I want to update statePrev to match state. To do this I need to know when all listeners is done, so my proposal to you is that I want to be able to specify a callback function that is executed after all listeners is done. Like in the code below.\r\n\r\n``` javascript\r\ntoggle(e) {\r\n  state.isOpen = !state.isOpen\r\n  state.trigger('update').done(function() {\r\n    // All callbacks listening to this event is now done\r\n    statePrev = _.cloneDeep(state)\r\n    state.trigger('updated')\r\n  })\r\n}\r\n\r\nstate.on('update', function() {\r\n  console.log('isOpen changed from ' + statePrev.isOpen + ' to ' + state.isOpen)\r\n})\r\n\r\n```\r\n\r\nIf we have multiple triggers of the same event only the done-callback that triggered the event should be called when done. (if there is one)\r\n\r\nWhat do you think about this suggestion?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/riot/riot/issues/comments/139891760","html_url":"https://github.com/riot/riot/issues/1201#issuecomment-139891760","issue_url":"https://api.github.com/repos/riot/riot/issues/1201","id":139891760,"user":{"login":"AndreasHeintze","id":2219544,"avatar_url":"https://avatars.githubusercontent.com/u/2219544?v=3","gravatar_id":"","url":"https://api.github.com/users/AndreasHeintze","html_url":"https://github.com/AndreasHeintze","followers_url":"https://api.github.com/users/AndreasHeintze/followers","following_url":"https://api.github.com/users/AndreasHeintze/following{/other_user}","gists_url":"https://api.github.com/users/AndreasHeintze/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreasHeintze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreasHeintze/subscriptions","organizations_url":"https://api.github.com/users/AndreasHeintze/orgs","repos_url":"https://api.github.com/users/AndreasHeintze/repos","events_url":"https://api.github.com/users/AndreasHeintze/events{/privacy}","received_events_url":"https://api.github.com/users/AndreasHeintze/received_events","type":"User","site_admin":false},"created_at":"2015-09-13T16:13:51Z","updated_at":"2015-09-13T16:13:51Z","body":"Ha ha, well you are right. I must have been thinking asynchronously too much lately. Thanks!"}}