{"action":"created","issue":{"url":"https://api.github.com/repos/taskcluster/aws-provisioner/issues/20","labels_url":"https://api.github.com/repos/taskcluster/aws-provisioner/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/taskcluster/aws-provisioner/issues/20/comments","events_url":"https://api.github.com/repos/taskcluster/aws-provisioner/issues/20/events","html_url":"https://github.com/taskcluster/aws-provisioner/pull/20","id":73584624,"number":20,"title":"Refactor to lists","user":{"login":"jhford","id":607353,"avatar_url":"https://avatars.githubusercontent.com/u/607353?v=3","gravatar_id":"","url":"https://api.github.com/users/jhford","html_url":"https://github.com/jhford","followers_url":"https://api.github.com/users/jhford/followers","following_url":"https://api.github.com/users/jhford/following{/other_user}","gists_url":"https://api.github.com/users/jhford/gists{/gist_id}","starred_url":"https://api.github.com/users/jhford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhford/subscriptions","organizations_url":"https://api.github.com/users/jhford/orgs","repos_url":"https://api.github.com/users/jhford/repos","events_url":"https://api.github.com/users/jhford/events{/privacy}","received_events_url":"https://api.github.com/users/jhford/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-06T10:31:35Z","updated_at":"2015-05-07T01:52:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/taskcluster/aws-provisioner/pulls/20","html_url":"https://github.com/taskcluster/aws-provisioner/pull/20","diff_url":"https://github.com/taskcluster/aws-provisioner/pull/20.diff","patch_url":"https://github.com/taskcluster/aws-provisioner/pull/20.patch"},"body":"Didn't actually make a pull request last night... Please don't merge this."},"comment":{"url":"https://api.github.com/repos/taskcluster/aws-provisioner/issues/comments/99677359","html_url":"https://github.com/taskcluster/aws-provisioner/pull/20#issuecomment-99677359","issue_url":"https://api.github.com/repos/taskcluster/aws-provisioner/issues/20","id":99677359,"user":{"login":"jonasfj","id":149732,"avatar_url":"https://avatars.githubusercontent.com/u/149732?v=3","gravatar_id":"","url":"https://api.github.com/users/jonasfj","html_url":"https://github.com/jonasfj","followers_url":"https://api.github.com/users/jonasfj/followers","following_url":"https://api.github.com/users/jonasfj/following{/other_user}","gists_url":"https://api.github.com/users/jonasfj/gists{/gist_id}","starred_url":"https://api.github.com/users/jonasfj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonasfj/subscriptions","organizations_url":"https://api.github.com/users/jonasfj/orgs","repos_url":"https://api.github.com/users/jonasfj/repos","events_url":"https://api.github.com/users/jonasfj/events{/privacy}","received_events_url":"https://api.github.com/users/jonasfj/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T01:52:55Z","updated_at":"2015-05-07T01:52:55Z","body":"My comments here are just nits... I have nothing seriously wrong... This looks pretty neat...\r\n\r\nI do wish to encourage flattening the objects representing spot requests and EC2 instances... Even if we just keep them as JSON objects. Following reasons:\r\n 1. No need to check if `Placement` is present before doing `Placement.AvailabilityZone`\r\n 2. Easier to access\r\n 3. Ability rename into more JS-like names (clearly distinguishing raw from internal representation)\r\n 4. Ability to clearly outline which properties we keep in our representation\r\n 5. Easier to filter\r\n\r\nExample of utility method I would implement:\r\n```js\r\nAwsManager.prototype.instances = function(predicate) {\r\n  if (!predicate) {\r\n    predicate = () => { return true; }; // Return all if predicate is missing\r\n  } else if (!(predicate instanceof Function)) {\r\n    var conditions = predicate;\r\n    predicate = (instance) => {\r\n      for(var key in conditions) {\r\n        var value = conditions[key];\r\n        if (value instanceof Array) {\r\n           return value.includes(instance[key]);\r\n        }\r\n        return instance[key] === value;\r\n      }\r\n      return true;\r\n    };\r\n  }\r\n  return this.__apiState.instances.filter(predicate);\r\n};\r\n\r\n// Usage example:\r\nthis.instances({\r\n  workerType:    workerType.workerType,\r\n  stateName:     states\r\n}).forEach(instance => {\r\n   // ....\r\n})\r\n\r\n// Instead of:\r\nvar instances = this.instancesOfType(workerType.workerType);\r\ninstances.forEach(function(instance) {\r\n    if (states.includes(instance.State.Name)) {\r\n      // ....\r\n    }\r\n})\r\n```\r\nYou have a lot of places where you do `filter` and `myArray.includes(...)`. By flattening properties this pattern would make a lot of these queries very readable.\r\n"}}