{"action":"created","issue":{"url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/910","repository_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage","labels_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/910/labels{/name}","comments_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/910/comments","events_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/910/events","html_url":"https://github.com/samselikoff/ember-cli-mirage/issues/910","id":180614070,"node_id":"MDU6SXNzdWUxODA2MTQwNzA=","number":910,"title":"Dynamic attrs in factories (functions) are called twice ","user":{"login":"cibernox","id":265339,"node_id":"MDQ6VXNlcjI2NTMzOQ==","avatar_url":"https://avatars2.githubusercontent.com/u/265339?v=4","gravatar_id":"","url":"https://api.github.com/users/cibernox","html_url":"https://github.com/cibernox","followers_url":"https://api.github.com/users/cibernox/followers","following_url":"https://api.github.com/users/cibernox/following{/other_user}","gists_url":"https://api.github.com/users/cibernox/gists{/gist_id}","starred_url":"https://api.github.com/users/cibernox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cibernox/subscriptions","organizations_url":"https://api.github.com/users/cibernox/orgs","repos_url":"https://api.github.com/users/cibernox/repos","events_url":"https://api.github.com/users/cibernox/events{/privacy}","received_events_url":"https://api.github.com/users/cibernox/received_events","type":"User","site_admin":false},"labels":[{"id":917563497,"node_id":"MDU6TGFiZWw5MTc1NjM0OTc=","url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/labels/Feature%20request","name":"Feature request","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-03T11:04:32Z","updated_at":"2018-07-27T18:40:06Z","closed_at":null,"author_association":"COLLABORATOR","body":"This arose while doing this:\n\n``` js\nFactory.extend({\n  id() {\n    return autoincrementalIdSharedBySeveralModels();\n  }\n});\n```\n\nThis code generates ids `[2, 4, 6, 8, 10]` etc...\n\nI dig a bit into why this happens and it's because mirage allows functions to be called out of order. By example, the next code is allowed:\n\n``` js\n  let BazFactory = Mirage.Factory.extend({\n    bar() {\n      return this.foo + 2; // This function calls foo as a property despite of being a function\n    },\n\n    baz: 6,\n\n    foo(i) {\n      return this.baz * i;\n    }\n  });\n```\n\nTo allow this mirage has to evaluate the functions twice, once to generate a Directed Acyclic Graph to know the exection order and the second to actually call them in order.\n\nIt's not easy to fix, but I think that if there functions were defined using `getters/setters`, none of this would be needed. However this outcome seems so obvious and the current solution so unintuitive that It makes me think that there is a reason I don't see why things are the way they are.\n\nWas it because of IE8 support? Other?\n"},"comment":{"url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/comments/408505122","html_url":"https://github.com/samselikoff/ember-cli-mirage/issues/910#issuecomment-408505122","issue_url":"https://api.github.com/repos/samselikoff/ember-cli-mirage/issues/910","id":408505122,"node_id":"MDEyOklzc3VlQ29tbWVudDQwODUwNTEyMg==","user":{"login":"samselikoff","id":2922250,"node_id":"MDQ6VXNlcjI5MjIyNTA=","avatar_url":"https://avatars1.githubusercontent.com/u/2922250?v=4","gravatar_id":"","url":"https://api.github.com/users/samselikoff","html_url":"https://github.com/samselikoff","followers_url":"https://api.github.com/users/samselikoff/followers","following_url":"https://api.github.com/users/samselikoff/following{/other_user}","gists_url":"https://api.github.com/users/samselikoff/gists{/gist_id}","starred_url":"https://api.github.com/users/samselikoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samselikoff/subscriptions","organizations_url":"https://api.github.com/users/samselikoff/orgs","repos_url":"https://api.github.com/users/samselikoff/repos","events_url":"https://api.github.com/users/samselikoff/events{/privacy}","received_events_url":"https://api.github.com/users/samselikoff/received_events","type":"User","site_admin":false},"created_at":"2018-07-27T18:40:06Z","updated_at":"2018-07-27T18:40:06Z","author_association":"OWNER","body":"I verified the behavior and agree it's confusing. I think at this point the path forward of changing the API to use getters instead of functions is a big enough change that it should be considered alongside other plans to change Mirage classes over to vanilla ES6 classes.\r\n\r\nFor now I'm going to mark this as a feature request, and we can come back to it when we move the rest of the objects over to ES6."}}
{"actor":{"display_login":"samselikoff"}}