-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve tree-shakeability (-13 B) (#2079)
* Remove prevDebounce init (-4 B) * Inline catchError declaration into options (-2 B) * Remove unused param (-6 B) * Reuse prevDebounce in enqueueRender (-1 B)
- Loading branch information
1 parent
1142fff
commit 63eb63c
Showing
4 changed files
with
47 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { enqueueRender } from '../component'; | ||
|
||
/** | ||
* Find the closest error boundary to a thrown error and call it | ||
* @param {object} error The thrown value | ||
* @param {import('../internal').VNode} vnode The vnode that threw | ||
* the error that was caught (except for unmounting when this parameter | ||
* is the highest parent that was being unmounted) | ||
*/ | ||
export function _catchError(error, vnode) { | ||
/** @type {import('../internal').Component} */ | ||
let component; | ||
|
||
for (; (vnode = vnode._parent); ) { | ||
if ((component = vnode._component) && !component._processingException) { | ||
try { | ||
if ( | ||
component.constructor && | ||
component.constructor.getDerivedStateFromError != null | ||
) { | ||
component.setState( | ||
component.constructor.getDerivedStateFromError(error) | ||
); | ||
} else if (component.componentDidCatch != null) { | ||
component.componentDidCatch(error); | ||
} else { | ||
continue; | ||
} | ||
return enqueueRender((component._pendingError = component)); | ||
} catch (e) { | ||
error = e; | ||
} | ||
} | ||
} | ||
|
||
throw error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { _catchError } from './diff/catch-error'; | ||
|
||
/** @type {import('./internal').Options} */ | ||
const options = {}; | ||
const options = { | ||
_catchError | ||
}; | ||
|
||
export default options; |