{"action":"created","issue":{"url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/issues/202","repository_url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster","labels_url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/issues/202/labels{/name}","comments_url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/issues/202/comments","events_url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/issues/202/events","html_url":"https://github.com/jirikavi/AngularJS-Toaster/issues/202","id":145714886,"number":202,"title":"Add handler to clear toasts","user":{"login":"phillipgreenii","id":757541,"avatar_url":"https://avatars.githubusercontent.com/u/757541?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipgreenii","html_url":"https://github.com/phillipgreenii","followers_url":"https://api.github.com/users/phillipgreenii/followers","following_url":"https://api.github.com/users/phillipgreenii/following{/other_user}","gists_url":"https://api.github.com/users/phillipgreenii/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipgreenii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipgreenii/subscriptions","organizations_url":"https://api.github.com/users/phillipgreenii/orgs","repos_url":"https://api.github.com/users/phillipgreenii/repos","events_url":"https://api.github.com/users/phillipgreenii/events{/privacy}","received_events_url":"https://api.github.com/users/phillipgreenii/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"Stabzs","id":11450848,"avatar_url":"https://avatars.githubusercontent.com/u/11450848?v=3","gravatar_id":"","url":"https://api.github.com/users/Stabzs","html_url":"https://github.com/Stabzs","followers_url":"https://api.github.com/users/Stabzs/followers","following_url":"https://api.github.com/users/Stabzs/following{/other_user}","gists_url":"https://api.github.com/users/Stabzs/gists{/gist_id}","starred_url":"https://api.github.com/users/Stabzs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stabzs/subscriptions","organizations_url":"https://api.github.com/users/Stabzs/orgs","repos_url":"https://api.github.com/users/Stabzs/repos","events_url":"https://api.github.com/users/Stabzs/events{/privacy}","received_events_url":"https://api.github.com/users/Stabzs/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2016-04-04T15:17:37Z","updated_at":"2016-04-12T19:21:51Z","closed_at":null,"body":"# Overview\r\n\r\nThis is related to #58, but with a simpler use case.  Currently, `toaster.pop()` doesn't return anything.  My suggestion is to make it return a handler that could be used to clear the specific toast message that was generated.  A usage example is as follows:\r\n```javascript\r\nvar handler = toaster.pop('close me!');\r\nhandler.clear();\r\n```\r\n## Simplistic Implementation\r\n```javascript\r\n\r\nfunction($rootScope, toasterConfig) {\r\n    this.pop = function(type, title, body, timeout, bodyOutputType, clickHandler, toasterId, showCloseButton, toastId, onHideCallback) {\r\n        // current implementation stays the same\r\n        // but not displayed for this example to save space\r\n        $rootScope.$emit('toaster-newToast', toasterId, toastId);\r\n        // new code starts here\r\n        var toast = this;\r\n        handler = {\r\n            clear: function() {\r\n                toast.clear(toasterId, toastId);\r\n            }\r\n        }\r\n        return handler;\r\n    };\r\n\r\n    this.clear = function(toasterId, toastId) {\r\n        $rootScope.$emit('toaster-clearToasts', toasterId, toastId);\r\n    };\r\n\r\n}\r\n```\r\n# Problems\r\nIt is unclear what should happen when a `toastId` is not specified.\r\n\r\n## No special handling\r\nIn this situation, the call to `toast.clear` would cause any message that didn't specify a `toastId` to be cleared.  This seems to violate the [principle of least astonishment](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).\r\n\r\n## Generate a surrogate key for all toasts.\r\nIn this situation, `toast.pop` could be updated so that if `toastId` is not specified, then one would be generated.  This ensures that `handler.clear()` will only clear the associated toast.  However, I don't know if this would break other parts of the code base.\r\n\r\n## Throw an error\r\nIn this situation, if the `toastId` is not specified, then `handler.clear()` throws an error.  This seems to be acceptable.\r\n\r\n# Summary\r\nFor my needs, any of the outlined solutions would work.  Can someone who is closer to the project provide direction on which solution if any should be implemented?"},"comment":{"url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/issues/comments/209062651","html_url":"https://github.com/jirikavi/AngularJS-Toaster/issues/202#issuecomment-209062651","issue_url":"https://api.github.com/repos/jirikavi/AngularJS-Toaster/issues/202","id":209062651,"user":{"login":"Stabzs","id":11450848,"avatar_url":"https://avatars.githubusercontent.com/u/11450848?v=3","gravatar_id":"","url":"https://api.github.com/users/Stabzs","html_url":"https://github.com/Stabzs","followers_url":"https://api.github.com/users/Stabzs/followers","following_url":"https://api.github.com/users/Stabzs/following{/other_user}","gists_url":"https://api.github.com/users/Stabzs/gists{/gist_id}","starred_url":"https://api.github.com/users/Stabzs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Stabzs/subscriptions","organizations_url":"https://api.github.com/users/Stabzs/orgs","repos_url":"https://api.github.com/users/Stabzs/repos","events_url":"https://api.github.com/users/Stabzs/events{/privacy}","received_events_url":"https://api.github.com/users/Stabzs/received_events","type":"User","site_admin":false},"created_at":"2016-04-12T19:21:51Z","updated_at":"2016-04-12T19:21:51Z","body":"@phillipgreenii that's very reasonable.  I've gone ahead and added in that feature as well.  In addition, I added support for each of the toaster pop helper methods."}}