{"action":"created","issue":{"url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/issues/99","repository_url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel","labels_url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/issues/99/comments","events_url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/issues/99/events","html_url":"https://github.com/sylvainpolletvillard/ObjectModel/issues/99","id":364938991,"node_id":"MDU6SXNzdWUzNjQ5Mzg5OTE=","number":99,"title":"Wrapping an object extended from ObjectModel inhibits that objects internal access to private members.","user":{"login":"Ravenex","id":10747095,"node_id":"MDQ6VXNlcjEwNzQ3MDk1","avatar_url":"https://avatars3.githubusercontent.com/u/10747095?v=4","gravatar_id":"","url":"https://api.github.com/users/Ravenex","html_url":"https://github.com/Ravenex","followers_url":"https://api.github.com/users/Ravenex/followers","following_url":"https://api.github.com/users/Ravenex/following{/other_user}","gists_url":"https://api.github.com/users/Ravenex/gists{/gist_id}","starred_url":"https://api.github.com/users/Ravenex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ravenex/subscriptions","organizations_url":"https://api.github.com/users/Ravenex/orgs","repos_url":"https://api.github.com/users/Ravenex/repos","events_url":"https://api.github.com/users/Ravenex/events{/privacy}","received_events_url":"https://api.github.com/users/Ravenex/received_events","type":"User","site_admin":false},"labels":[{"id":165147097,"node_id":"MDU6TGFiZWwxNjUxNDcwOTc=","url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-28T15:32:01Z","updated_at":"2018-09-28T19:09:01Z","closed_at":null,"author_association":"NONE","body":"I am trying to implement lazy loading of properties, or in my case groups of properties, from a database as that group of properties is needed. To accomplish this I want to wrap an object extended from ObjectModel in a outer proxy that can intercept the request for that property and load it before returning it's value. When I do this the object's ability to internally reference it's own private properties breaks. As an example:\r\n\r\n```javascript\r\nconst ObjectModel = require('objectmodel').ObjectModel\r\n\r\nclass Person extends ObjectModel({ name: String, _religion: [String], lazyProps: Array }) {\r\n  \r\n  getName() { return this.name }\r\n  getReligion() { return this._religion }\r\n  \r\n  isLazy(key) {return this.lazyProps.indexOf(key) != -1}\r\n  \r\n  lazyLoad(key) {\r\n    var val = \"Jewish\" //this would be loaded from a datastore\r\n    this[key] = val\r\n  }\r\n  \r\n}\r\n\r\nconst lazyProxy = {\r\n\r\n  get(o, key) {\r\n    if (typeof key === \"string\" && o.isLazy(key)) {\r\n      o.lazyLoad(key)\r\n    }\r\n    return o[key]\r\n  },\r\n      \r\n  set(o, key, val) {\r\n    if (typeof key === \"string\" && o.isLazy(key)) {\r\n      o.lazyLoad(key)\r\n    }\r\n      o[key] = val\r\n  }\r\n}\r\n\r\nconst Joe = new Person({ name: \"Joe\", lazyProps: [\"_religion\" ] })\r\nconsole.log(Joe.getName()) //Joe\r\nconsole.log(Joe.getReligion()) //undefined\r\nJoe.lazyLoad(\"_religion\")\r\nconsole.log(Joe.getReligion()) //Jewish\r\n\r\nconst Ann = new Person({ name: \"Ann\", lazyProps: [\"_religion\" ] })\r\nconst lazyAnn = new Proxy(Ann, lazyProxy)\r\nconsole.log(lazyAnn.getName()) //Ann\r\nconsole.log(lazyAnn.getReligion()) //expect Jewish but receive: TypeError: cannot access to private property _religion\r\n```"},"comment":{"url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/issues/comments/425536943","html_url":"https://github.com/sylvainpolletvillard/ObjectModel/issues/99#issuecomment-425536943","issue_url":"https://api.github.com/repos/sylvainpolletvillard/ObjectModel/issues/99","id":425536943,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNTUzNjk0Mw==","user":{"login":"sylvainpolletvillard","id":566536,"node_id":"MDQ6VXNlcjU2NjUzNg==","avatar_url":"https://avatars3.githubusercontent.com/u/566536?v=4","gravatar_id":"","url":"https://api.github.com/users/sylvainpolletvillard","html_url":"https://github.com/sylvainpolletvillard","followers_url":"https://api.github.com/users/sylvainpolletvillard/followers","following_url":"https://api.github.com/users/sylvainpolletvillard/following{/other_user}","gists_url":"https://api.github.com/users/sylvainpolletvillard/gists{/gist_id}","starred_url":"https://api.github.com/users/sylvainpolletvillard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sylvainpolletvillard/subscriptions","organizations_url":"https://api.github.com/users/sylvainpolletvillard/orgs","repos_url":"https://api.github.com/users/sylvainpolletvillard/repos","events_url":"https://api.github.com/users/sylvainpolletvillard/events{/privacy}","received_events_url":"https://api.github.com/users/sylvainpolletvillard/received_events","type":"User","site_admin":false},"created_at":"2018-09-28T19:09:01Z","updated_at":"2018-09-28T19:09:01Z","author_association":"OWNER","body":"yeah it's a bug, due to your isLazy method in the getter\r\n\r\nshorter way to reproduce:\r\n```js\r\nconst O = ObjectModel({ _priv: String }).defaults({\r\n  getPriv(){ \r\n     this.randomMethod();\r\n     return this._priv\r\n },\r\n  randomMethod(){ }\r\n})\r\n\r\nconst o = new O({ _priv: \"test\" })\r\no.getPriv(); // cannot access to private\r\n```\r\n\r\nbasically private access is granted for exactly one method call. If there is another method call in the getter, the access pass is exhausted and you get rejected.\r\n\r\nHard to find out but probably easy to fix. Stay tuned"}}
{"actor":{"display_login":"sylvainpolletvillard"}}