{"action":"created","issue":{"url":"https://api.github.com/repos/PolymerLabs/virtual-list/issues/8","repository_url":"https://api.github.com/repos/PolymerLabs/virtual-list","labels_url":"https://api.github.com/repos/PolymerLabs/virtual-list/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/PolymerLabs/virtual-list/issues/8/comments","events_url":"https://api.github.com/repos/PolymerLabs/virtual-list/issues/8/events","html_url":"https://github.com/PolymerLabs/virtual-list/issues/8","id":311778466,"number":8,"title":"Setter-only design vs. constructor arguments","user":{"login":"domenic","id":617481,"avatar_url":"https://avatars0.githubusercontent.com/u/617481?v=4","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-05T21:38:49Z","updated_at":"2018-04-06T22:02:54Z","closed_at":null,"author_association":"NONE","body":"https://github.com/PolymerLabs/virtual-list/blob/design/DESIGN.md has a lot of examples where you construct various classes by creating empty versions of them and then setting a bunch of properties with `Object.assign()`. This is strange in a few ways:\r\n\r\n- It implies that the objects are fully functional even before these properties are set. Is that true? I find it hard to believe that a `VirtualList` with no `layout` or `items` is still a fully-functional `VirtualList`.\r\n- It implies that these properties can be changed at any time and the class will respond appropriately. (E.g., changing `container`.)\r\n- It implies that these properties can all be changed independently of each other. (Maybe this is true, I'm not sure.)\r\n\r\nInstead I would suggest making these constructor arguments: `new VirtualList({ layout, container, items, newChildFn })`, etc. This ensures that you cannot construct an instance of the class without setting them, and setting them all at once, together.\r\n\r\nThis also allows more fine-grained separation so that things which _can_ be set and modified later and independently (say, `VirtualRepeater`'s `first`?) are exposed as public getter/setter pairs."},"comment":{"url":"https://api.github.com/repos/PolymerLabs/virtual-list/issues/comments/379397062","html_url":"https://github.com/PolymerLabs/virtual-list/issues/8#issuecomment-379397062","issue_url":"https://api.github.com/repos/PolymerLabs/virtual-list/issues/8","id":379397062,"user":{"login":"valdrinkoshi","id":6173664,"avatar_url":"https://avatars3.githubusercontent.com/u/6173664?v=4","gravatar_id":"","url":"https://api.github.com/users/valdrinkoshi","html_url":"https://github.com/valdrinkoshi","followers_url":"https://api.github.com/users/valdrinkoshi/followers","following_url":"https://api.github.com/users/valdrinkoshi/following{/other_user}","gists_url":"https://api.github.com/users/valdrinkoshi/gists{/gist_id}","starred_url":"https://api.github.com/users/valdrinkoshi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valdrinkoshi/subscriptions","organizations_url":"https://api.github.com/users/valdrinkoshi/orgs","repos_url":"https://api.github.com/users/valdrinkoshi/repos","events_url":"https://api.github.com/users/valdrinkoshi/events{/privacy}","received_events_url":"https://api.github.com/users/valdrinkoshi/received_events","type":"User","site_admin":false},"created_at":"2018-04-06T22:02:54Z","updated_at":"2018-04-06T22:02:54Z","author_association":"COLLABORATOR","body":"Constructor arguments serve well instantiations like this:\r\n```js\r\nconst Repeats = Superclass => class extends Superclass {\r\n  constructor(config) {\r\n    super();\r\n    this._container = config.container;\r\n    this._container.style.position = 'relative';\r\n  }\r\n};\r\n\r\nclass MyList extends Repeats(class {});\r\n\r\nconst list = new MyList({\r\n  container: document.body,\r\n  // ...\r\n});\r\n```\r\n\r\nBut this won't work for custom elements because it forces them to have `container` defined at construct time, e.g. if we want to set `container` to be `this` or `this.shadowRoot`:\r\n```js\r\nclass MyList extends Repeats(HTMLElement) {\r\n  constructor() {\r\n    super({\r\n      container: this, \r\n    });\r\n  }\r\n}\r\n\r\ncustomElements.define('my-list', MyList);\r\n```"}}
{"actor":{"display_login":"valdrinkoshi"}}