withJob has workingProps state to ignore an old work's late resolve.#47
withJob has workingProps state to ignore an old work's late resolve.#47dehypnosis wants to merge 1 commit intoctrlplusb:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #47 +/- ##
=======================================
Coverage 94.17% 94.17%
=======================================
Files 5 5
Lines 103 103
Branches 31 31
=======================================
Hits 97 97
Misses 6 6
Continue to review full report at Codecov.
|
|
Hey @dehypnosis! Thanks for this. It's a really interesting case to cover. I had a quick look and I think in principal it makes sense. One question though - do you think it would be safer to do a shallow equality check on the props object instead? Can we guarantee React always returns the same "wrapping" object holding the props? What do you think? I really appreciate the help 👍 |
resolveWork = (props) => {
this.setState({ completed: false, data: null, error: null, workingProps: props })
...
if (isPromise(workDefinition)) {
// Asynchronous result.
return workDefinition
.then((data) => {
if (this.unmounted || this.state.workingProps !== props) {
...Thank you for the answer. Did I rightly recognize your point? |
To solve issue #45 (Need to abort an old work when a new work started).
I made a simple solution.
When new work starts, store the reference of current props object as wokringProps in the component.
And when job finished, compare the current props reference (in closure) with the stored wokringProps reference.
If references are not equal, just ignore the result as like ignore unmounted component
I'd like you to take a look at it.