-
Notifications
You must be signed in to change notification settings - Fork 50.8k
Inline fbjs/lib/EventListener dependency #11402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ var { | |
| getStackAddendumByWorkInProgressFiber, | ||
| } = require('shared/ReactFiberComponentTreeHook'); | ||
| var { | ||
| wrapEventListener, | ||
| invokeGuardedCallback, | ||
| hasCaughtError, | ||
| clearCaughtError, | ||
|
|
@@ -1273,6 +1274,17 @@ module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>( | |
| // TODO: Everything below this is written as if it has been lifted to the | ||
| // renderers. I'll do this in a follow-up. | ||
|
|
||
| // Ensure performAsyncWork gets wrapped. This currently needs to be lazy because | ||
| // we use dynamic injection. TODO: Make this eagerly wrapping this callback once | ||
| // we have static injection. | ||
| let hasCallbackBeenScheduled: boolean = false; | ||
| function ensureCallbackWrapped() { | ||
| if (!hasCallbackBeenScheduled) { | ||
| performAsyncWork = wrapEventListener('reactAsyncWork', performAsyncWork); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pretty unfortunate but we have to make these lazy. I also don't want to keep wrapping each individual call to rIC because this wrapper is pretty heavy. |
||
| hasCallbackBeenScheduled = true; | ||
| } | ||
| } | ||
|
|
||
| // Linked-list of roots | ||
| let firstScheduledRoot: FiberRoot | null = null; | ||
| let lastScheduledRoot: FiberRoot | null = null; | ||
|
|
@@ -1354,6 +1366,7 @@ module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>( | |
| performWork(Sync, null); | ||
| } else if (!isCallbackScheduled) { | ||
| isCallbackScheduled = true; | ||
| ensureCallbackWrapped(); | ||
| scheduleDeferredCallback(performAsyncWork); | ||
| } | ||
| } | ||
|
|
@@ -1434,9 +1447,9 @@ module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>( | |
| nextFlushedExpirationTime = highestPriorityWork; | ||
| } | ||
|
|
||
| function performAsyncWork(dl) { | ||
| let performAsyncWork = function(dl) { | ||
| performWork(NoWork, dl); | ||
| } | ||
| }; | ||
|
|
||
| function performWork(minExpirationTime: ExpirationTime, dl: Deadline | null) { | ||
| deadline = dl; | ||
|
|
@@ -1466,6 +1479,7 @@ module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>( | |
| // If there's work left over, schedule a new callback. | ||
| if (nextFlushedRoot !== null && !isCallbackScheduled) { | ||
| isCallbackScheduled = true; | ||
| ensureCallbackWrapped(); | ||
| scheduleDeferredCallback(performAsyncWork); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ const ReactErrorUtils = { | |
| 'Injected invokeGuardedCallback() must be a function.', | ||
| ); | ||
| invokeGuardedCallback = injectedErrorUtils.invokeGuardedCallback; | ||
| wrapEventListener = injectedErrorUtils.wrapEventListener; | ||
| }, | ||
| }, | ||
|
|
||
|
|
@@ -57,6 +58,13 @@ const ReactErrorUtils = { | |
| invokeGuardedCallback.apply(ReactErrorUtils, arguments); | ||
| }, | ||
|
|
||
| /** | ||
| * Wrap a callback in whatever logic it needs. Used in FB to polyfill Promises. | ||
| */ | ||
| wrapEventListener: function<T>(name: string, callback: T): T { | ||
| return wrapEventListener(name, callback); | ||
| }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gaearon I built this the same way as the other injection since they're related. Feel free to split them out when we move to static injection. At the very least it seems like we could move to something like what |
||
|
|
||
| /** | ||
| * Same as invokeGuardedCallback, but instead of returning an error, it stores | ||
| * it in a global so it can be rethrown by `rethrowCaughtError` later. | ||
|
|
@@ -116,6 +124,10 @@ const ReactErrorUtils = { | |
| }, | ||
| }; | ||
|
|
||
| let wrapEventListener = function<T>(name: string, callback: T): T { | ||
| return callback; | ||
| }; | ||
|
|
||
| let invokeGuardedCallback = function(name, func, context, a, b, c, d, e, f) { | ||
| ReactErrorUtils._hasCaughtError = false; | ||
| ReactErrorUtils._caughtError = null; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning(false,?