-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(hadron-app-registry): make serviceLocator stricter to limit the…
… potential misuse (#5535) * chore(hadron-app-registry): make serviceLocator stricter to limit the potential misuse * chore(app-registry): reset the inProgress flag in finally to make sure that runtime check state is correct when it's done running even if it throws
- Loading branch information
1 parent
0581c27
commit 5444b83
Showing
24 changed files
with
310 additions
and
129 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { createServiceLocator } from 'hadron-app-registry'; | ||
import type { MongoDBInstance } from 'mongodb-instance-model'; | ||
import { createContext, useContext } from 'react'; | ||
|
||
export const InstanceContext = createContext<MongoDBInstance | null>(null); | ||
|
||
export const MongoDBInstanceProvider = InstanceContext.Provider; | ||
|
||
export const mongoDBInstanceLocator = (): MongoDBInstance => { | ||
const instance = useContext(InstanceContext); | ||
if (!instance) { | ||
throw new Error('No MongoDBInstance available in this context'); | ||
export const mongoDBInstanceLocator = createServiceLocator( | ||
function mongoDBInstanceLocator(): MongoDBInstance { | ||
const instance = useContext(InstanceContext); | ||
if (!instance) { | ||
throw new Error('No MongoDBInstance available in this context'); | ||
} | ||
return instance; | ||
} | ||
return instance; | ||
}; | ||
); | ||
|
||
export type { MongoDBInstance }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.