Skip to content

Commit

Permalink
Add queueMicrotask to HostConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jan 26, 2021
1 parent cf96b27 commit 39bd8c3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ export function getChildHostContext() {

export const scheduleTimeout = setTimeout;
export const cancelTimeout = clearTimeout;
// TODO: Implement for ART.
export const queueMicrotask = undefined;
export const noTimeout = -1;

export function shouldSetTextContent(type, props) {
Expand Down
15 changes: 15 additions & 0 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ export const scheduleTimeout: any =
export const cancelTimeout: any =
typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
export const noTimeout = -1;
export const queueMicrotask: (Function => void) | undefined =
typeof queueMicrotask === 'function'
? queueMicrotask
: typeof Promise !== 'undefined'
? callback =>
Promise.resolve(null)
.then(callback)
.catch(handleErrorInNextTick)
: scheduleTimeout;

function handleErrorInNextTick(error) {
setTimeout(() => {
throw error;
});
}

// -------------------
// Mutation
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ export const warnsIfNotActing = false;

export const scheduleTimeout = setTimeout;
export const cancelTimeout = clearTimeout;
// TODO: implement for React Native.
export const queueMicrotask = undefined;
export const noTimeout = -1;

// -------------------
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ export const warnsIfNotActing = true;

export const scheduleTimeout = setTimeout;
export const cancelTimeout = clearTimeout;
// TODO: Implement for React Native.
export const queueMicrotask = undefined;
export const noTimeout = -1;

export function shouldSetTextContent(type: string, props: Props): boolean {
Expand Down
15 changes: 15 additions & 0 deletions packages/react-test-renderer/src/ReactTestHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ export const warnsIfNotActing = true;

export const scheduleTimeout = setTimeout;
export const cancelTimeout = clearTimeout;
export const queueMicrotask =
typeof queueMicrotask === 'function'
? queueMicrotask
: typeof Promise !== 'undefined'
? callback =>
Promise.resolve(null)
.then(callback)
.catch(handleErrorInNextTick)
: scheduleTimeout;

function handleErrorInNextTick(error) {
setTimeout(() => {
throw error;
});
}
export const noTimeout = -1;

// -------------------
Expand Down

0 comments on commit 39bd8c3

Please sign in to comment.