Skip to content

Commit 39bd8c3

Browse files
committed
Add queueMicrotask to HostConfigs
1 parent cf96b27 commit 39bd8c3

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

packages/react-art/src/ReactARTHostConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ export function getChildHostContext() {
329329

330330
export const scheduleTimeout = setTimeout;
331331
export const cancelTimeout = clearTimeout;
332+
// TODO: Implement for ART.
333+
export const queueMicrotask = undefined;
332334
export const noTimeout = -1;
333335

334336
export function shouldSetTextContent(type, props) {

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,21 @@ export const scheduleTimeout: any =
384384
export const cancelTimeout: any =
385385
typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
386386
export const noTimeout = -1;
387+
export const queueMicrotask: (Function => void) | undefined =
388+
typeof queueMicrotask === 'function'
389+
? queueMicrotask
390+
: typeof Promise !== 'undefined'
391+
? callback =>
392+
Promise.resolve(null)
393+
.then(callback)
394+
.catch(handleErrorInNextTick)
395+
: scheduleTimeout;
396+
397+
function handleErrorInNextTick(error) {
398+
setTimeout(() => {
399+
throw error;
400+
});
401+
}
387402

388403
// -------------------
389404
// Mutation

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ export const warnsIfNotActing = false;
347347

348348
export const scheduleTimeout = setTimeout;
349349
export const cancelTimeout = clearTimeout;
350+
// TODO: implement for React Native.
351+
export const queueMicrotask = undefined;
350352
export const noTimeout = -1;
351353

352354
// -------------------

packages/react-native-renderer/src/ReactNativeHostConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ export const warnsIfNotActing = true;
246246

247247
export const scheduleTimeout = setTimeout;
248248
export const cancelTimeout = clearTimeout;
249+
// TODO: Implement for React Native.
250+
export const queueMicrotask = undefined;
249251
export const noTimeout = -1;
250252

251253
export function shouldSetTextContent(type: string, props: Props): boolean {

packages/react-test-renderer/src/ReactTestHostConfig.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ export const warnsIfNotActing = true;
220220

221221
export const scheduleTimeout = setTimeout;
222222
export const cancelTimeout = clearTimeout;
223+
export const queueMicrotask =
224+
typeof queueMicrotask === 'function'
225+
? queueMicrotask
226+
: typeof Promise !== 'undefined'
227+
? callback =>
228+
Promise.resolve(null)
229+
.then(callback)
230+
.catch(handleErrorInNextTick)
231+
: scheduleTimeout;
232+
233+
function handleErrorInNextTick(error) {
234+
setTimeout(() => {
235+
throw error;
236+
});
237+
}
223238
export const noTimeout = -1;
224239

225240
// -------------------

0 commit comments

Comments
 (0)