Hooks - #3
Conversation
|
Nice! Any reason you did not include the
I'd like to track that in #2 , let's first focus on fixing the goal of this PR. |
| // Only run reactiveFn if the hooks have not change, or are not falsy. | ||
| if (areHookInputsEqual(deps, refs.previousDeps)) { | ||
| runReactiveFn(); | ||
| } |
There was a problem hiding this comment.
else { c.stop() }
IMHO the computation should be stopped as fast as you can to avoid async related issues.
Who knows when react decides to update the component which then calls dispose().
There was a problem hiding this comment.
That makes sense - I also wonder if areHookInputsEqual(deps, refs.previousDeps) is overkill - the only real case I think we need to check for here is if either deps or refs.previousDeps are falsy, because the enclosed value of dep and the refs value should never really change between the last run (which did an equality check) and the reactive function execution. In other words, they will always be made equal before the computation runs, because if deps changes, the computation is stopped/restarted and those values made equal at the same time.
There was a problem hiding this comment.
I agree, if deps and prevDeps are different, they are always handled within react's lifecycles.
I don't see any reason why !deps || !refs.previousDeps should work.
|
The code looks good, I'll make some in-depth tests by tomorrow, I don't want to risk a third PR for this. |
|
Hey, this all looks great! If you guys need any help I'd be happy to if I can. |
|
This PR also solves the issue I had with the increased number of subscriptions as explained in Everything seems to work! |
useRef.