-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide singletons #46
base: master
Are you sure you want to change the base?
Conversation
if (this.isSingletonProvided(Klass)) { | ||
throw new Error(`The singleton ${Klass.name} is already provided.`); | ||
} | ||
this.providedSingletons.set(Klass, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we refactor so the same map is used for provides and overrides?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on second thought maybe not, you might want to override before providing.
@@ -115,6 +153,12 @@ export class App { | |||
if (this.hasSingleton(Klass)) { | |||
return this.getExistingSingleton(Klass); | |||
} | |||
if (!this.isSingletonProvided(Klass)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe at locator level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
*/ | ||
load<T>(Klass: ConstructorOrFactory<App, T>): void { | ||
this.getSingleton(Klass); // force initialization; | ||
return; | ||
if (this.isSingletonProvided(Klass)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it should be just getSingleton (multiple loads should be ok)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to re-do this with a bit of thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redo this PR or the loading-once-or-twice mechanics? Fine with both really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to think whether we want to allow loading plugins within plugins, because thats what implies multiple load calls are OK.
Introduces the concept of "providing singletons".
Modules will be expected to provide stuff to other modules, and doing
app#getSingleton
will throw if stuff wasn't previously provided.Still WIP.