{"action":"closed","issue":{"url":"https://api.github.com/repos/canjs/canjs/issues/2529","repository_url":"https://api.github.com/repos/canjs/canjs","labels_url":"https://api.github.com/repos/canjs/canjs/issues/2529/labels{/name}","comments_url":"https://api.github.com/repos/canjs/canjs/issues/2529/comments","events_url":"https://api.github.com/repos/canjs/canjs/issues/2529/events","html_url":"https://github.com/canjs/canjs/issues/2529","id":179654162,"number":2529,"title":"Improve Map value() functions ~13","user":{"login":"dylanrtt","id":11302736,"avatar_url":"https://avatars2.githubusercontent.com/u/11302736?v=3","gravatar_id":"","url":"https://api.github.com/users/dylanrtt","html_url":"https://github.com/dylanrtt","followers_url":"https://api.github.com/users/dylanrtt/followers","following_url":"https://api.github.com/users/dylanrtt/following{/other_user}","gists_url":"https://api.github.com/users/dylanrtt/gists{/gist_id}","starred_url":"https://api.github.com/users/dylanrtt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylanrtt/subscriptions","organizations_url":"https://api.github.com/users/dylanrtt/orgs","repos_url":"https://api.github.com/users/dylanrtt/repos","events_url":"https://api.github.com/users/dylanrtt/events{/privacy}","received_events_url":"https://api.github.com/users/dylanrtt/received_events","type":"User","site_admin":false},"labels":[{"id":17958203,"url":"https://api.github.com/repos/canjs/canjs/labels/bug","name":"bug","color":"ee0701","default":true},{"id":286126501,"url":"https://api.github.com/repos/canjs/canjs/labels/needs%20a%20hero","name":"needs a hero","color":"000000","default":false},{"id":435069105,"url":"https://api.github.com/repos/canjs/canjs/labels/p4","name":"p4","color":"f9d0c4","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-28T00:50:53Z","updated_at":"2017-04-12T01:50:42Z","closed_at":"2017-04-12T01:50:42Z","body":"Default `value()` functions within can-map-define should have better rules that allow reading from other `value()` functions and initial values provided to the map constructor (e.g., `new can.Map({a: 5})`). The current behavior doesn't work as I would expect.\n\nIn the following example, the default `value()` function for `a` is evaluated first. It tries to read `this.attr('b')`, but `b` doesn't have a value yet, so it returns `undefined`. In this scenario, I think it would be reasonable for the `value()` function of `b` to be read during the `this.attr('b')` call to resolve it, similar to how computes work.\n\n``` js\nvar Map = can.Map.extend({\n  define: {\n    a: {\n      value: function() {\n        return this.attr('b');\n      }\n    },\n    b: {\n      value: function() {\n        return 5;\n      }\n    }\n  }\n});\n\nvar map = new Map();\n\nconsole.log(map.attr()); // { b: 5 }\n```\n\nhttp://jsbin.com/liquwuroge/edit?js,console\n\nI thought that instantiating the map instance with an initial value for `b` might resolve the problem, but when I do that, the `value()` functions never seem to be able to read any of the initial values (same effect as above).\n\nAlso, if I instantiate a 2nd map from the same constructor with an initial value for `b` like this:\n\n``` js\nvar map = new Map({b: 10});\n\nconsole.log(map.attr()); // { a: 5, b: 10 }\n```\n\nThe `value()` function of `a` seems to have received a cached default value for the `b` (5) rather than using the provided initial value (10).\n\nUnfortunately, the lack of versatility with `value()` leads me to use `get()` more often, which can be a problem because computes introduce performance overhead.\n"}}
{"actor":{"display_login":"justinbmeyer"}}