{"action":"closed","issue":{"url":"https://api.github.com/repos/Simonwep/pickr/issues/24","repository_url":"https://api.github.com/repos/Simonwep/pickr","labels_url":"https://api.github.com/repos/Simonwep/pickr/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/Simonwep/pickr/issues/24/comments","events_url":"https://api.github.com/repos/Simonwep/pickr/issues/24/events","html_url":"https://github.com/Simonwep/pickr/issues/24","id":342461728,"node_id":"MDU6SXNzdWUzNDI0NjE3Mjg=","number":24,"title":"Consider factory functions","user":{"login":"SaulDoesCode","id":10322221,"node_id":"MDQ6VXNlcjEwMzIyMjIx","avatar_url":"https://avatars1.githubusercontent.com/u/10322221?v=4","gravatar_id":"","url":"https://api.github.com/users/SaulDoesCode","html_url":"https://github.com/SaulDoesCode","followers_url":"https://api.github.com/users/SaulDoesCode/followers","following_url":"https://api.github.com/users/SaulDoesCode/following{/other_user}","gists_url":"https://api.github.com/users/SaulDoesCode/gists{/gist_id}","starred_url":"https://api.github.com/users/SaulDoesCode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SaulDoesCode/subscriptions","organizations_url":"https://api.github.com/users/SaulDoesCode/orgs","repos_url":"https://api.github.com/users/SaulDoesCode/repos","events_url":"https://api.github.com/users/SaulDoesCode/events{/privacy}","received_events_url":"https://api.github.com/users/SaulDoesCode/received_events","type":"User","site_admin":false},"labels":[{"id":961188083,"node_id":"MDU6TGFiZWw5NjExODgwODM=","url":"https://api.github.com/repos/Simonwep/pickr/labels/improvement","name":"improvement","color":"cce85c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-07-18T19:31:43Z","updated_at":"2018-08-18T16:15:30Z","closed_at":"2018-08-18T16:15:30Z","author_association":"CONTRIBUTOR","body":"Instead of using classes, consider using factory functions instead because then there would be no need for ``new`` and also by avoiding the use of ``this`` one would eliminate the need for ``_.bindClassUnderscoreFunctions(this);`` completely. \r\n\r\nOverall should you consider using factory functions it may actually simplify the codebase and improve the code's portability as functions require no backwards transpilation to ES5 while at the same time improving composability by avoiding ``this`` and working only with plain objects instead of class instances.\r\n\r\nNo need to make everything a factory function but for something like the ``new Selectable();`` helper it could be an improvement.\r\n\r\nThis is what the ``selectable.js`` helper would look like\r\n```js\r\nimport * as _ from './../lib/utils';\r\n\r\nexport default function Selectable(opt) {\r\n    const selectable = {\r\n        // Assign default values\r\n        options: Object.assign({\r\n            onchange: () => 0,\r\n            className: ''\r\n        }, opt),\r\n\r\n        _ontap(evt) {\r\n            const opt = selectable.options;\r\n\r\n            opt.elements.forEach(e => e.classList.remove(opt.className));\r\n            evt.target.classList.add(opt.className);\r\n\r\n            opt.onchange();\r\n        },\r\n\r\n        destroy() {\r\n            _.off(selectable.options.elements, 'click', selectable._ontap);\r\n        }\r\n    }\r\n\r\n    _.on(selectable.options.elements, 'click', selectable._ontap);\r\n\r\n    return selectable;\r\n}\r\n```\r\nNote: changing this file in the codebase as it stands to the above code will not be breaking as calling ``new (function () {})`` does not cause an error.\r\n\r\nPerhaps read [this article](https://medium.com/javascript-scene/javascript-factory-functions-with-es6-4d224591a8b1) from Eric Elliott for more information on factory functions."}}
{"actor":{"display_login":"Simonwep"}}