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
14d75c42
Commit
14d75c42
authored
Mar 08, 2021
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `propTypes` handling in `service-context.js`
We no longer set `propTypes` on components.
parent
3ab698f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
22 deletions
+1
-22
service-context.js
src/sidebar/service-context.js
+1
-7
service-context-test.js
src/sidebar/test/service-context-test.js
+0
-15
No files found.
src/sidebar/service-context.js
View file @
14d75c42
...
@@ -44,7 +44,7 @@ export const ServiceContext = createContext(fallbackInjector);
...
@@ -44,7 +44,7 @@ export const ServiceContext = createContext(fallbackInjector);
* Wrap a React component to inject any services it depends upon as props.
* Wrap a React component to inject any services it depends upon as props.
*
*
* Components declare their service dependencies in an `injectedProps` static
* Components declare their service dependencies in an `injectedProps` static
* property.
These services also need to be declared in `propTypes`.
* property.
*
*
* Any props which are passed directly will override injected props.
* Any props which are passed directly will override injected props.
*
*
...
@@ -97,12 +97,6 @@ export function withServices(Component) {
...
@@ -97,12 +97,6 @@ export function withServices(Component) {
const
wrappedName
=
Component
.
displayName
||
Component
.
name
;
const
wrappedName
=
Component
.
displayName
||
Component
.
name
;
Wrapper
.
displayName
=
`withServices(
${
wrappedName
}
)`
;
Wrapper
.
displayName
=
`withServices(
${
wrappedName
}
)`
;
// Forward the prop types, except for those expected to be injected via
// the `ServiceContext`.
Wrapper
.
propTypes
=
{
...
Component
.
propTypes
};
Component
.
injectedProps
.
forEach
(
prop
=>
{
delete
Wrapper
.
propTypes
[
prop
];
});
return
Wrapper
;
return
Wrapper
;
}
}
...
...
src/sidebar/test/service-context-test.js
View file @
14d75c42
import
{
mount
}
from
'enzyme'
;
import
{
mount
}
from
'enzyme'
;
import
{
render
}
from
'preact'
;
import
{
render
}
from
'preact'
;
import
propTypes
from
'prop-types'
;
import
{
ServiceContext
,
withServices
,
useService
}
from
'../service-context'
;
import
{
ServiceContext
,
withServices
,
useService
}
from
'../service-context'
;
...
@@ -40,20 +39,6 @@ describe('sidebar/service-context', () => {
...
@@ -40,20 +39,6 @@ describe('sidebar/service-context', () => {
assert
.
calledWith
(
injector
.
get
,
'aService'
);
assert
.
calledWith
(
injector
.
get
,
'aService'
);
});
});
it
(
'copies propTypes except for injected properties to wrapper'
,
()
=>
{
function
TestComponent
()
{}
TestComponent
.
propTypes
=
{
notInjected
:
propTypes
.
string
,
injected
:
propTypes
.
string
,
};
TestComponent
.
injectedProps
=
[
'injected'
];
const
Wrapped
=
withServices
(
TestComponent
);
assert
.
deepEqual
(
Wrapped
.
propTypes
,
{
notInjected
:
propTypes
.
string
});
assert
.
isUndefined
(
Wrapped
.
injectedProps
);
});
it
(
'does not look up services if they are passed as props'
,
()
=>
{
it
(
'does not look up services if they are passed as props'
,
()
=>
{
const
testService
=
{};
const
testService
=
{};
const
injector
=
{
const
injector
=
{
...
...
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