{"action":"created","issue":{"url":"https://api.github.com/repos/rdking/proposal-class-members/issues/3","repository_url":"https://api.github.com/repos/rdking/proposal-class-members","labels_url":"https://api.github.com/repos/rdking/proposal-class-members/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/rdking/proposal-class-members/issues/3/comments","events_url":"https://api.github.com/repos/rdking/proposal-class-members/issues/3/events","html_url":"https://github.com/rdking/proposal-class-members/issues/3","id":377101176,"node_id":"MDU6SXNzdWUzNzcxMDExNzY=","number":3,"title":"Declarative own-state objects.","user":{"login":"rdking","id":2289634,"node_id":"MDQ6VXNlcjIyODk2MzQ=","avatar_url":"https://avatars0.githubusercontent.com/u/2289634?v=4","gravatar_id":"","url":"https://api.github.com/users/rdking","html_url":"https://github.com/rdking","followers_url":"https://api.github.com/users/rdking/followers","following_url":"https://api.github.com/users/rdking/following{/other_user}","gists_url":"https://api.github.com/users/rdking/gists{/gist_id}","starred_url":"https://api.github.com/users/rdking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdking/subscriptions","organizations_url":"https://api.github.com/users/rdking/orgs","repos_url":"https://api.github.com/users/rdking/repos","events_url":"https://api.github.com/users/rdking/events{/privacy}","received_events_url":"https://api.github.com/users/rdking/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":64,"created_at":"2018-11-03T22:55:29Z","updated_at":"2018-11-15T01:58:23Z","closed_at":null,"author_association":"OWNER","body":"@ljharb @mbrowne\r\n\r\nIf I understand what's going on in #1, the 2nd problem being targeted is the need to declare a property initialized with an object, and having that object be an instance-specific copy each time. Is this what you guys really want? If so, this is something good that I see as worth doing, but I have a much better approach than the problematic implementation that exists in class-fields. It doesn't introduce \"fields\" of any kind. It doesn't require trying to make a declarative thing from something inherently imperative either. \r\n\r\nHere's the idea:\r\nSince this proposal resolves all property initializers at the time of `class` definition evaluation, should any property be initialized with an object, that objects will be wrapped in a Membrane with a handler that traps any attempt to modify any portion of the object. When any such trap triggers, the property is duplicated onto the instance with the original value, and the modification operation is forwarded onto the instance. \r\n\r\nBasically, this:\r\n```js\r\nclass A {\r\n  x = 0;\r\n  y = {lat: 1, long: 2};\r\n  constructor() {\r\n      this.y.lat += 3;\r\n  }\r\n}\r\n```\r\nwould become this:\r\n```js\r\nvar A = (function() {\r\n  var handler = {\r\n    duplicateAndForward(op, target, prop, ...args) {\r\n      var retval = false;\r\n      var obj = {lat: 1, long: 2};\r\n      this.owner[this.root] = obj;\r\n      for (var p of this.path) {\r\n        obj = obj[p];\r\n      }\r\n      return Reflect[op](obj, prop, ...args);\r\n    },\r\n    defineProperty(target, property, descriptor) {\r\n      if (!this.owner) {\r\n  \t    retval = false;\r\n      }\r\n      else {\r\n        retval = this.duplicateAndForward(\"defineProperty\", target, property, descriptor);\r\n      }\r\n      return retval;\r\n    },\r\n    deleteProperty(target, property) {\r\n      return this.duplicateAndForward(\"deleteProperty\", target, property, descriptor);\r\n    },\r\n    get(target, prop, receiver) {\r\n      var retval = Reflect.get(target, prop, receiver);\r\n      if (retval && ['function','object'].includes(typeof(retval))) {\r\n        retval = Proxy(retval, {\r\n          owner: this.owner || target,\r\n          prop,\r\n          path: [].concat(this.path, [this.prop]),\r\n          __proto__: handler\r\n        });\r\n      }\r\n      return retval;\r\n    },\r\n    set(target, prop, value, receiver) {\r\n      return this.duplicateAndForward('set', target, prop, value, receiver);\r\n    }\r\n  };\r\n  return class A {\r\n    x = 0;\r\n    get y() { return new Proxy({lat: 1, long: 2}, {owner: this, root: 'y', prop: \"y\", path: [], __proto__: handler}) }\r\n    set y(value) { Object.defineProperty(this, \"y\", {\r\n      enumerable: true,\r\n      configurable: true,\r\n      writable: true,\r\n      value\r\n    }); }\r\n    constructor() {\r\n      this.y.lat += 3;\r\n    }\r\n  }\r\n})();\r\n```\r\n\r\nSo what do you guys think?"},"comment":{"url":"https://api.github.com/repos/rdking/proposal-class-members/issues/comments/438887786","html_url":"https://github.com/rdking/proposal-class-members/issues/3#issuecomment-438887786","issue_url":"https://api.github.com/repos/rdking/proposal-class-members/issues/3","id":438887786,"node_id":"MDEyOklzc3VlQ29tbWVudDQzODg4Nzc4Ng==","user":{"login":"ljharb","id":45469,"node_id":"MDQ6VXNlcjQ1NDY5","avatar_url":"https://avatars1.githubusercontent.com/u/45469?v=4","gravatar_id":"","url":"https://api.github.com/users/ljharb","html_url":"https://github.com/ljharb","followers_url":"https://api.github.com/users/ljharb/followers","following_url":"https://api.github.com/users/ljharb/following{/other_user}","gists_url":"https://api.github.com/users/ljharb/gists{/gist_id}","starred_url":"https://api.github.com/users/ljharb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ljharb/subscriptions","organizations_url":"https://api.github.com/users/ljharb/orgs","repos_url":"https://api.github.com/users/ljharb/repos","events_url":"https://api.github.com/users/ljharb/events{/privacy}","received_events_url":"https://api.github.com/users/ljharb/received_events","type":"User","site_admin":false},"created_at":"2018-11-15T01:58:23Z","updated_at":"2018-11-15T01:58:23Z","author_association":"NONE","body":"Why the constructor property? Convention. Not because it must be there; and the fact that it’s not required means it’s not an important part of the mental model."}}
{"actor":{"display_login":"ljharb"}}