{"action":"opened","issue":{"url":"https://api.github.com/repos/KrisSiegel/msngr.js/issues/48","labels_url":"https://api.github.com/repos/KrisSiegel/msngr.js/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/KrisSiegel/msngr.js/issues/48/comments","events_url":"https://api.github.com/repos/KrisSiegel/msngr.js/issues/48/events","html_url":"https://github.com/KrisSiegel/msngr.js/issues/48","id":120534153,"number":48,"title":"Revamp option functionality to become more intuitive middleware","user":{"login":"KrisSiegel","id":1885826,"avatar_url":"https://avatars.githubusercontent.com/u/1885826?v=3","gravatar_id":"","url":"https://api.github.com/users/KrisSiegel","html_url":"https://github.com/KrisSiegel","followers_url":"https://api.github.com/users/KrisSiegel/followers","following_url":"https://api.github.com/users/KrisSiegel/following{/other_user}","gists_url":"https://api.github.com/users/KrisSiegel/gists{/gist_id}","starred_url":"https://api.github.com/users/KrisSiegel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KrisSiegel/subscriptions","organizations_url":"https://api.github.com/users/KrisSiegel/orgs","repos_url":"https://api.github.com/users/KrisSiegel/repos","events_url":"https://api.github.com/users/KrisSiegel/events{/privacy}","received_events_url":"https://api.github.com/users/KrisSiegel/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/KrisSiegel/msngr.js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/KrisSiegel/msngr.js/milestones/1","html_url":"https://github.com/KrisSiegel/msngr.js/milestones/msngr%204.0.0","labels_url":"https://api.github.com/repos/KrisSiegel/msngr.js/milestones/1/labels","id":1437897,"number":1,"title":"msngr 4.0.0","description":null,"creator":{"login":"KrisSiegel","id":1885826,"avatar_url":"https://avatars.githubusercontent.com/u/1885826?v=3","gravatar_id":"","url":"https://api.github.com/users/KrisSiegel","html_url":"https://github.com/KrisSiegel","followers_url":"https://api.github.com/users/KrisSiegel/followers","following_url":"https://api.github.com/users/KrisSiegel/following{/other_user}","gists_url":"https://api.github.com/users/KrisSiegel/gists{/gist_id}","starred_url":"https://api.github.com/users/KrisSiegel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KrisSiegel/subscriptions","organizations_url":"https://api.github.com/users/KrisSiegel/orgs","repos_url":"https://api.github.com/users/KrisSiegel/repos","events_url":"https://api.github.com/users/KrisSiegel/events{/privacy}","received_events_url":"https://api.github.com/users/KrisSiegel/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":0,"state":"open","created_at":"2015-12-01T16:59:24Z","updated_at":"2015-12-05T06:13:00Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2015-12-05T06:13:00Z","updated_at":"2015-12-05T06:13:00Z","closed_at":null,"body":"Right now developers can create middleware-like functionality but it's called \"options\" and it requires being done inside of msngr's internal structures which isn't intuitive and the naming just doesn't make sense. So the existing adding and using of options should be transformed into the following:\r\n\r\n- [ ] Create a top level method called ```msngr.middleware(key, fn, force)```. This method is how a developer can create a middleware for msngr.\r\n    - ```key``` is a string that will be used when a developer wants to enable this middleware\r\n    - ```fn``` is a function that is called for the middleware. It's definition is as follows:\r\n    ```javascript\r\n    msngr.middleware(\"test\", function(message, payload, next) {\r\n        next(); // optionally accepts a new payload to replace the old payload\r\n    });\r\n    ```\r\n    - ```force``` is an optional boolean that indicates whether this middleware should be forced on all messages. By default this is ```false``` which means a developer has to explicitly tell their emits to use whatever middleware(s) they want but when this is true it will execute no matter what.\r\n- [ ] Remove the existing way of adding options via the internal API exposed when extending\r\n- [ ] Add a ```msngr(\"topic\").use(middleware)``` function to the message object which specifies, via a string, what middleware to use. Works almost exactly like the existing ```msngr(\"topic\").option(key)``` except ```use()``` won't be able to accept any type of special options (those should go into configurations should they be necessary)."}}