You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
I'm also not really a fan of the Error thrown in the MySky constructor. I would make it possible for multiple MySky instances to be created, but structure the code in a way that only one is ever created. That's more easily said than done of course but perhaps in this case the easiest thing to do is use a global variable.
What's the reason only one MySky instance should get created by the way? Perhaps there's no real good reason and we don't have to care about all of this.
if (MySky.instance) {
return MySky.instance
}
this.pendingPermissions = permissions;
MySky.instance = this
}
Setting MySky.instance is also a responsibility of the constructor and not of New because using New is optional and someone can easily do
constms1=newMySky(...)constms2=newMySky(...)
and it will just work. Also returning the existing instance is the standard practice with factories and other singleton implementations (the usual is a getInstance() as PJ mentioned).
(We'll also need to change the MySky.instance = new MySky(connector, permissions, hostDomain, currentPortalUrl); on line 217.)
I just read the discussion we had about this a month ago - I had forgotten about it. The way I see it we have two options:
Stop calling this a singleton and make is a standard class.
Implement a proper singleton.
I guess either one works and neither will take very long. I believe the suggested code above solves all issues we have with the singleton approach - it ensures that only one MySky object can be created and it also doesn't thow the error which PJ didn't like.
I'm also not really a fan of the
Error
thrown in the MySky constructor. I would make it possible for multiple MySky instances to be created, but structure the code in a way that only one is ever created. That's more easily said than done of course but perhaps in this case the easiest thing to do is use a global variable.What's the reason only one MySky instance should get created by the way? Perhaps there's no real good reason and we don't have to care about all of this.
Originally posted by @peterjan in #361 (comment)
The text was updated successfully, but these errors were encountered: