{"action":"created","issue":{"url":"https://api.github.com/repos/canjs/can-define/issues/85","repository_url":"https://api.github.com/repos/canjs/can-define","labels_url":"https://api.github.com/repos/canjs/can-define/issues/85/labels{/name}","comments_url":"https://api.github.com/repos/canjs/can-define/issues/85/comments","events_url":"https://api.github.com/repos/canjs/can-define/issues/85/events","html_url":"https://github.com/canjs/can-define/issues/85","id":185402490,"number":85,"title":"Make it possible for a property to be bound when any other properties are bound","user":{"login":"justinbmeyer","id":78602,"avatar_url":"https://avatars.githubusercontent.com/u/78602?v=3","gravatar_id":"","url":"https://api.github.com/users/justinbmeyer","html_url":"https://github.com/justinbmeyer","followers_url":"https://api.github.com/users/justinbmeyer/followers","following_url":"https://api.github.com/users/justinbmeyer/following{/other_user}","gists_url":"https://api.github.com/users/justinbmeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/justinbmeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinbmeyer/subscriptions","organizations_url":"https://api.github.com/users/justinbmeyer/orgs","repos_url":"https://api.github.com/users/justinbmeyer/repos","events_url":"https://api.github.com/users/justinbmeyer/events{/privacy}","received_events_url":"https://api.github.com/users/justinbmeyer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/canjs/can-define/labels/P2","name":"P2","color":"f9d0c4"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-26T14:02:17Z","updated_at":"2016-10-26T16:44:58Z","closed_at":null,"body":"Say I have a stream that's tracking the behavior of another value:\r\n\r\n```js\r\nMyMap = DefineMap.extend({\r\n  previousValues: {\r\n    stream: function(){\r\n      return this.stream(\".value\").scan(function(prev, next){\r\n        prev.push(next);\r\n      },[])\r\n    }\r\n  },\r\n  value: \"*\"\r\n});\r\n```\r\n\r\n\r\nIt's common that `previousValues` might not be used in the page, and therefore not bound and tracking changes in `value`.  When `previousValues` is eventually bound, it will be an empty Array.\r\n\r\nTo fix this, I'm proposing some form of \"activeWhenAnyPropertyOnObservableIsBound\" flag (obviously not that name) that `get` and `stream` can use like:\r\n\r\n```js\r\nMyMap = DefineMap.extend({\r\n  previousValues: {\r\n    stream: function(){\r\n      return this.stream(\".value\").scan(function(prev, next){\r\n        prev.push(next);\r\n      },[])\r\n    },\r\n    activeWhenAnyPropertyOnObservableIsBound: true\r\n  },\r\n  value: \"*\"\r\n});\r\n```\r\n\r\nThis will activate (by binding) that property when any other property is bound.  This means that if `value` is bound, `previousValues` will become \"active\".\r\n\r\n\r\nThis is similar conceptually to __weak__ references and maps. This is why I propose the following identifier(s):\r\n\r\n - `weakBind: true`\r\n - `autoCompute: true`\r\n\r\n## Technical Considerations\r\n\r\nThis might be tricky to get right with `_bindings` in https://github.com/canjs/can-event/blob/master/lifecycle/lifecycle.js.    \r\n\r\nWhen `.on(\"value\")` happens, we'll want to make sure `_eventSetup` is called and bind on any `weakBind` properties.  However, those bindings will presumably increase `_bindings`.  When `.off(\"value\")`, we need to make sure `_eventTeardown` is called.\r\n\r\nIt's possible `can-connect/can/map` already does something like this.  I feel like I've encountered this problem before.  It might be good to formalize it."},"comment":{"url":"https://api.github.com/repos/canjs/can-define/issues/comments/256408235","html_url":"https://github.com/canjs/can-define/issues/85#issuecomment-256408235","issue_url":"https://api.github.com/repos/canjs/can-define/issues/85","id":256408235,"user":{"login":"justinbmeyer","id":78602,"avatar_url":"https://avatars.githubusercontent.com/u/78602?v=3","gravatar_id":"","url":"https://api.github.com/users/justinbmeyer","html_url":"https://github.com/justinbmeyer","followers_url":"https://api.github.com/users/justinbmeyer/followers","following_url":"https://api.github.com/users/justinbmeyer/following{/other_user}","gists_url":"https://api.github.com/users/justinbmeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/justinbmeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinbmeyer/subscriptions","organizations_url":"https://api.github.com/users/justinbmeyer/orgs","repos_url":"https://api.github.com/users/justinbmeyer/repos","events_url":"https://api.github.com/users/justinbmeyer/events{/privacy}","received_events_url":"https://api.github.com/users/justinbmeyer/received_events","type":"User","site_admin":false},"created_at":"2016-10-26T16:44:58Z","updated_at":"2016-10-26T16:44:58Z","body":"@BigAB Thinking about it like:\r\n\r\n```\r\nweak === will not hold onto this\r\n```\r\n\r\nTo me means, that `weakMap.set(key, SOMETHING)` should be a `no-op`, that `weakMap` will never hold onto that reference.  \r\n\r\nOnly by including the additional information:\r\n\r\n```\r\nweak === will ONLY hold onto this if someone else does\r\n```\r\n\r\ndoes the nature and behavior of `weak` have meaning.\r\n\r\n"}}
{"actor":{"display_login":"justinbmeyer"}}