Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
41e57fde
Commit
41e57fde
authored
Mar 22, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Mar 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Infer service names from component props when calling withServices HOC
parent
6713383b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
9 deletions
+7
-9
service-context.tsx
src/sidebar/service-context.tsx
+7
-9
No files found.
src/sidebar/service-context.tsx
View file @
41e57fde
...
...
@@ -58,7 +58,7 @@ export const ServiceContext = createContext(fallbackInjector);
*/
export
function
withServices
<
Props
extends
Record
<
string
,
unknown
>
,
ServiceName
extends
string
,
ServiceName
extends
string
&
keyof
Props
,
>
(
Component
:
ComponentType
<
Props
>
,
serviceNames
:
ServiceName
[],
...
...
@@ -71,17 +71,15 @@ export function withServices<
// Inject services, unless they have been overridden by props passed from
// the parent component.
const
services
:
Record
<
string
,
unknown
>
=
{};
const
services
:
Partial
<
Record
<
ServiceName
,
unknown
>
>
=
{};
for
(
const
service
of
serviceNames
)
{
// Debugging check to make sure the store is used correctly.
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
if
(
service
===
'store'
)
{
if
(
process
.
env
.
NODE_ENV
!==
'production'
&&
service
===
'store'
)
{
/* istanbul ignore next - Ignore debug code */
throw
new
Error
(
'Do not use `withServices` to inject the `store` service. Use the `useStore` hook instead'
,
);
}
}
if
(
!
(
service
in
props
))
{
services
[
service
]
=
injector
.
get
(
service
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment