Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e0a106

Browse files
authored
Updated: Support React-Hot-Loader compatibility (#1168)
* fix: react-hot-loader compatibility* Fix test runner breakingThe test runner script tried to pass the Jest config asstringified JSON, but that was breaking for me somehow.Sidestepped the problem by writing the settings to disk insteadand pointing Jest to that file.
1 parent63af52f commit6e0a106

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test/**/lcov.info
1010
test/**/lcov-report
1111
test/react/*/test/**/*.spec.js
1212
test/react/**/src
13+
test/jest-config.json
1314
lcov.info
1415

1516
lib/core/metadata.js

‎src/components/connectAdvanced.js‎

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export default function connectAdvanced(
120120
const{ pure}=connectOptions
121121

122122
letOuterBaseComponent=Component
123-
letFinalWrappedComponent=WrappedComponent
124123

125124
if(pure){
126125
OuterBaseComponent=PureComponent
@@ -131,15 +130,25 @@ export default function connectAdvanced(
131130
letlastState
132131
letlastDerivedProps
133132
letlastStore
133+
letlastSelectorFactoryOptions
134134
letsourceSelector
135135

136-
returnfunctionselectDerivedProps(state,props,store){
136+
returnfunctionselectDerivedProps(
137+
state,
138+
props,
139+
store,
140+
selectorFactoryOptions
141+
){
137142
if(pure&&lastProps===props&&lastState===state){
138143
returnlastDerivedProps
139144
}
140145

141-
if(store!==lastStore){
146+
if(
147+
store!==lastStore||
148+
lastSelectorFactoryOptions!==selectorFactoryOptions
149+
){
142150
lastStore=store
151+
lastSelectorFactoryOptions=selectorFactoryOptions
143152
sourceSelector=selectorFactory(
144153
store.dispatch,
145154
selectorFactoryOptions
@@ -157,14 +166,23 @@ export default function connectAdvanced(
157166
}
158167

159168
functionmakeChildElementSelector(){
160-
letlastChildProps,lastForwardRef,lastChildElement
169+
letlastChildProps,lastForwardRef,lastChildElement,lastComponent
161170

162-
returnfunctionselectChildElement(childProps,forwardRef){
163-
if(childProps!==lastChildProps||forwardRef!==lastForwardRef){
171+
returnfunctionselectChildElement(
172+
WrappedComponent,
173+
childProps,
174+
forwardRef
175+
){
176+
if(
177+
childProps!==lastChildProps||
178+
forwardRef!==lastForwardRef||
179+
lastComponent!==WrappedComponent
180+
){
164181
lastChildProps=childProps
165182
lastForwardRef=forwardRef
183+
lastComponent=WrappedComponent
166184
lastChildElement=(
167-
<FinalWrappedComponent{...childProps}ref={forwardRef}/>
185+
<WrappedComponent{...childProps}ref={forwardRef}/>
168186
)
169187
}
170188

@@ -182,7 +200,14 @@ export default function connectAdvanced(
182200
)
183201
this.selectDerivedProps=makeDerivedPropsSelector()
184202
this.selectChildElement=makeChildElementSelector()
185-
this.renderWrappedComponent=this.renderWrappedComponent.bind(this)
203+
this.indirectRenderWrappedComponent=this.indirectRenderWrappedComponent.bind(
204+
this
205+
)
206+
}
207+
208+
indirectRenderWrappedComponent(value){
209+
// calling renderWrappedComponent on prototype from indirectRenderWrappedComponent bound to `this`
210+
returnthis.renderWrappedComponent(value)
186211
}
187212

188213
renderWrappedComponent(value){
@@ -206,10 +231,15 @@ export default function connectAdvanced(
206231
letderivedProps=this.selectDerivedProps(
207232
storeState,
208233
wrapperProps,
209-
store
234+
store,
235+
selectorFactoryOptions
210236
)
211237

212-
returnthis.selectChildElement(derivedProps,forwardedRef)
238+
returnthis.selectChildElement(
239+
WrappedComponent,
240+
derivedProps,
241+
forwardedRef
242+
)
213243
}
214244

215245
render(){
@@ -222,7 +252,7 @@ export default function connectAdvanced(
222252

223253
return(
224254
<ContextToUse.Consumer>
225-
{this.renderWrappedComponent}
255+
{this.indirectRenderWrappedComponent}
226256
</ContextToUse.Consumer>
227257
)
228258
}

‎test/run-tests.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
constnpmRun=require('npm-run')
2+
constfs=require('fs')
3+
constpath=require('path')
24
constLATEST_VERSION='16.6'
35
constversion=process.env.REACT||LATEST_VERSION
46

@@ -27,7 +29,13 @@ if (version.toLowerCase() === 'all') {
2729
}
2830
}
2931

32+
constconfigFilePath=path.join(__dirname,'jest-config.json')
33+
34+
fs.writeFileSync(configFilePath,JSON.stringify(jestConfig))
35+
36+
constcommandLine=`jest -c "${configFilePath}"${process.argv.slice(2).join(' ')}`
37+
3038
npmRun.execSync(
31-
`jest -c '${JSON.stringify(jestConfig)}'${process.argv.slice(2).join(' ')}`,
39+
commandLine,
3240
{stdio:'inherit'}
3341
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp