{"action":"opened","issue":{"url":"https://api.github.com/repos/HelloZeroNet/ZeroNet/issues/1777","repository_url":"https://api.github.com/repos/HelloZeroNet/ZeroNet","labels_url":"https://api.github.com/repos/HelloZeroNet/ZeroNet/issues/1777/labels{/name}","comments_url":"https://api.github.com/repos/HelloZeroNet/ZeroNet/issues/1777/comments","events_url":"https://api.github.com/repos/HelloZeroNet/ZeroNet/issues/1777/events","html_url":"https://github.com/HelloZeroNet/ZeroNet/issues/1777","id":379540744,"node_id":"MDU6SXNzdWUzNzk1NDA3NDQ=","number":1777,"title":"Provide a function for when site_info has been resolved","user":{"login":"anoadragon453","id":1342360,"node_id":"MDQ6VXNlcjEzNDIzNjA=","avatar_url":"https://avatars1.githubusercontent.com/u/1342360?v=4","gravatar_id":"","url":"https://api.github.com/users/anoadragon453","html_url":"https://github.com/anoadragon453","followers_url":"https://api.github.com/users/anoadragon453/followers","following_url":"https://api.github.com/users/anoadragon453/following{/other_user}","gists_url":"https://api.github.com/users/anoadragon453/gists{/gist_id}","starred_url":"https://api.github.com/users/anoadragon453/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anoadragon453/subscriptions","organizations_url":"https://api.github.com/users/anoadragon453/orgs","repos_url":"https://api.github.com/users/anoadragon453/repos","events_url":"https://api.github.com/users/anoadragon453/events{/privacy}","received_events_url":"https://api.github.com/users/anoadragon453/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-11T16:51:27Z","updated_at":"2018-11-11T16:51:27Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Consider the following example:\r\n\r\n```\r\nclass ZeroApp extends ZeroFrame {\r\n  onOpenWebsocket() {\r\n    zeroframe.cmd(\"wrapperSetLocalStorage\", {\"score\": 500}, null);\r\n  }\r\n}\r\n\r\nzeroapp = new ZeroApp()\r\n```\r\n\r\nIf one runs this, they get `TypeError: this.site_info is null`. That is because even though the Websocket has been opened, (I assume) the ZeroNet daemon has not yet returned `site_info` to the UiWrapper.\r\n\r\nWhile this is just a toy example, I have run into problems with this on ZeroLSTN, often needing to use the following trick just to ensure `site_info` has been loaded before performing some tasks:\r\n\r\n```\r\nclass ZeroApp extends ZeroFrame {\r\n  onOpenWebsocket() {\r\n    setTimeout(() => {\r\n      zeroframe.cmd(\"wrapperSetLocalStorage\", {\"score\": 500}, null);\r\n    }, 50);\r\n  }\r\n}\r\n\r\nzeroapp = new ZeroApp()\r\n```\r\n\r\n`site_info` was resolved, but we potentially lost a few ms in the process.\r\n\r\nIs it possible to provide a `ready()` function, either one that can be overridden or one that is run when `site_info` has been retrieved. It could even work like the following:\r\n\r\n```\r\nconst zeroframe = new ZeroFrame();\r\n\r\nzeroframe.onReady = function() {\r\n  console.log(\"Ready!\");\r\n}\r\n```"}}
{"actor":{"display_login":"anoadragon453"}}