{"action":"opened","issue":{"url":"https://api.github.com/repos/protocoolmx/spokesman/issues/4","repository_url":"https://api.github.com/repos/protocoolmx/spokesman","labels_url":"https://api.github.com/repos/protocoolmx/spokesman/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/protocoolmx/spokesman/issues/4/comments","events_url":"https://api.github.com/repos/protocoolmx/spokesman/issues/4/events","html_url":"https://github.com/protocoolmx/spokesman/issues/4","id":208042200,"number":4,"title":"Make \"data\" and \"error\" events predetermined ","user":{"login":"joshuamarquez","id":12701027,"avatar_url":"https://avatars.githubusercontent.com/u/12701027?v=3","gravatar_id":"","url":"https://api.github.com/users/joshuamarquez","html_url":"https://github.com/joshuamarquez","followers_url":"https://api.github.com/users/joshuamarquez/followers","following_url":"https://api.github.com/users/joshuamarquez/following{/other_user}","gists_url":"https://api.github.com/users/joshuamarquez/gists{/gist_id}","starred_url":"https://api.github.com/users/joshuamarquez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshuamarquez/subscriptions","organizations_url":"https://api.github.com/users/joshuamarquez/orgs","repos_url":"https://api.github.com/users/joshuamarquez/repos","events_url":"https://api.github.com/users/joshuamarquez/events{/privacy}","received_events_url":"https://api.github.com/users/joshuamarquez/received_events","type":"User","site_admin":false},"labels":[{"id":539058636,"url":"https://api.github.com/repos/protocoolmx/spokesman/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":{"login":"jesusp","id":3613442,"avatar_url":"https://avatars.githubusercontent.com/u/3613442?v=3","gravatar_id":"","url":"https://api.github.com/users/jesusp","html_url":"https://github.com/jesusp","followers_url":"https://api.github.com/users/jesusp/followers","following_url":"https://api.github.com/users/jesusp/following{/other_user}","gists_url":"https://api.github.com/users/jesusp/gists{/gist_id}","starred_url":"https://api.github.com/users/jesusp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jesusp/subscriptions","organizations_url":"https://api.github.com/users/jesusp/orgs","repos_url":"https://api.github.com/users/jesusp/repos","events_url":"https://api.github.com/users/jesusp/events{/privacy}","received_events_url":"https://api.github.com/users/jesusp/received_events","type":"User","site_admin":false},"assignees":[{"login":"jesusp","id":3613442,"avatar_url":"https://avatars.githubusercontent.com/u/3613442?v=3","gravatar_id":"","url":"https://api.github.com/users/jesusp","html_url":"https://github.com/jesusp","followers_url":"https://api.github.com/users/jesusp/followers","following_url":"https://api.github.com/users/jesusp/following{/other_user}","gists_url":"https://api.github.com/users/jesusp/gists{/gist_id}","starred_url":"https://api.github.com/users/jesusp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jesusp/subscriptions","organizations_url":"https://api.github.com/users/jesusp/orgs","repos_url":"https://api.github.com/users/jesusp/repos","events_url":"https://api.github.com/users/jesusp/events{/privacy}","received_events_url":"https://api.github.com/users/jesusp/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2017-02-16T07:34:54Z","updated_at":"2017-02-16T07:34:54Z","closed_at":null,"body":"Currently `data` and `error` events are optional for custom emitters, I have the proposal to make them default, how is this? well, we could use `onProviderData` implementation in custom emitters just to validate provider data and mutate it if necessary and let `ServiceEmitter` emit that validated and maybe mutated data with `data` event by default. We already have a way to know if data is valid (the return value of `onProviderData`)  but we need a way to mutate data in custom emitter and pass it to `ServiceEmitter`, an option is using a callback, another is making sure we always modify data as an object so this way it will be the same data object managed by `ServiceEmitter`.\r\n\r\nI like the most the callback option so I will elaborate it below.\r\n\r\nIf we decide go for this option there will be no need for `onProviderData` to return a boolean for\r\nvalidating data, the callback would be responsible for this. I imagine the callback taking two arguments.\r\n\r\nExample: \r\n\r\n```javascript\r\n// Implementation in `ServiceEmitter`.\r\nthis.onProviderData(clonedData, (error, validatedData) => {\r\n\r\n  if (error) {\r\n    return this.emit('error', error);\r\n  }\r\n\r\n  this._data = validatedData;\r\n  this.emit('data', this._data);\r\n});\r\n\r\n// Implementation in custom emitter.\r\nonProviderData (data, cb) {\r\n\r\n  // Do some validation...\r\n  \r\n  return cb(null, dataModified);\r\n}\r\n```\r\n\r\nThe `error` event emitted above covers only validation scenario, for error coming from provider via `onProviderError` we could emit by default error received on `error` event. A custom emitter will always have the option to override `ServiceEmitter` implementation of this method.\r\n\r\n```javascript\r\n// ServiceEmitter.js\r\nonProviderError (error) {\r\n  this.emit('error', error);\r\n}\r\n```\r\n\r\nWith the implementations below we assure data validated and modified in custom emitter is also the one available in `ServiceEmitter` besides we have `data` and `error` events as default.\r\n\r\nSo far this seems to me the best option, I am open to new proposals.\r\n"}}
{"actor":{"display_login":"joshuamarquez"}}