Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(chore) - Remove scheduleTask helpers (#861)

* Replace scheduleTask helper with inline Promise.resolve()

The scheduleTask helper was useful because globally we can't
tell whether `Promise` has been polyfilled for IE11 yet.
However, where this is called we _can_ already be sure of
it being polyfilled, which we do assume in other places
of the codebase.
Therefore it's safe to replace the `scheduleTask` polyfill
with a simple inline `Promise.resolve().then(fn)` call, which
is also more obvious.

* Add Changeset

* Fix up type error in test

authored by

Phil Plückthun and committed by
GitHub
c3dbd2a7 f468f6df

+14 -17
+6
.changeset/tiny-tomatoes-bow.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + '@urql/core': patch 4 + --- 5 + 6 + Replace unnecessary `scheduleTask` polyfill with inline `Promise.resolve().then(fn)` calls.
+2 -2
exchanges/graphcache/src/offlineExchange.test.ts
··· 261 261 262 262 flush!(); 263 263 expect(dispatchOperationSpy).toHaveBeenCalledTimes(1); 264 - expect(dispatchOperationSpy.mock.calls[0][0]!.key).toEqual(1); 265 - expect(dispatchOperationSpy.mock.calls[0][0]!.query).toEqual( 264 + expect((dispatchOperationSpy.mock.calls[0][0] as any).key).toEqual(1); 265 + expect((dispatchOperationSpy.mock.calls[0][0] as any).query).toEqual( 266 266 mutationOp.query 267 267 ); 268 268 });
+1 -2
exchanges/graphcache/src/store/data.ts
··· 19 19 20 20 import { makeDict } from '../helpers/dict'; 21 21 import { invariant, currentDebugStack } from '../helpers/help'; 22 - import { scheduleTask } from './defer'; 23 22 24 23 type Dict<T> = Record<string, T>; 25 24 type KeyMap<T> = Map<string, T>; ··· 136 135 // Schedule deferred tasks if we haven't already 137 136 if (process.env.NODE_ENV !== 'test' && !data.defer) { 138 137 data.defer = true; 139 - scheduleTask(() => { 138 + Promise.resolve().then(() => { 140 139 initDataState('write', data, null); 141 140 gc(); 142 141 persistData();
-4
exchanges/graphcache/src/store/defer.ts
··· 1 - export const scheduleTask: (fn: () => void) => void = 2 - process.env.NODE_ENV === 'production' && typeof Promise !== 'undefined' 3 - ? Promise.prototype.then.bind(Promise.resolve()) 4 - : fn => setTimeout(fn, 0);
+5 -4
packages/core/src/client.ts
··· 41 41 toSuspenseSource, 42 42 withPromise, 43 43 maskTypename, 44 - scheduleTask, 45 44 noop, 46 45 } from './utils'; 47 46 ··· 91 90 maskTypename: boolean; 92 91 93 92 // These are internals to be used to keep track of operations 94 - dispatchOperation: (operation?: Operation) => void; 93 + dispatchOperation: (operation?: Operation | void) => void; 95 94 operations$: Source<Operation>; 96 95 results$: Source<OperationResult>; 97 96 activeOperations = Object.create(null) as ActiveOperations; ··· 126 125 this.operations$ = operations$; 127 126 128 127 let isOperationBatchActive = false; 129 - this.dispatchOperation = (operation?: Operation) => { 128 + this.dispatchOperation = (operation?: Operation | void) => { 130 129 isOperationBatchActive = true; 131 130 if (operation) nextOperation(operation); 132 131 while ((operation = this.queue.shift())) nextOperation(operation); ··· 138 137 // operation's exchange results 139 138 if ((this.activeOperations[operation.key] || 0) > 0) { 140 139 this.queue.push(operation); 141 - if (!isOperationBatchActive) scheduleTask(this.dispatchOperation); 140 + if (!isOperationBatchActive) { 141 + Promise.resolve().then(this.dispatchOperation); 142 + } 142 143 } 143 144 }; 144 145
-4
packages/core/src/utils/defer.ts
··· 1 - export const scheduleTask: (fn: () => void) => void = 2 - typeof Promise !== 'undefined' 3 - ? Promise.prototype.then.bind(Promise.resolve()) 4 - : fn => setTimeout(fn, 0);
-1
packages/core/src/utils/index.ts
··· 6 6 export * from './stringifyVariables'; 7 7 export * from './maskTypename'; 8 8 export * from './withPromise'; 9 - export * from './defer'; 10 9 11 10 export const noop = () => { 12 11 /* noop */