Skip to content

Commit

Permalink
Relay: Remove fbjs/lib/ErrorUtils Dependency
Browse files Browse the repository at this point in the history
Reviewed By: kassens

Differential Revision: D27608944

fbshipit-source-id: 9120f8db8a06f9dd2f5eb01c2faf44ea9d990a33
  • Loading branch information
yungsters authored and facebook-github-bot committed Apr 7, 2021
1 parent 1a50269 commit 5ed076e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 7 additions & 4 deletions packages/relay-runtime/store/RelayPublishQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

'use strict';

const ErrorUtils = require('ErrorUtils');
const RelayReader = require('./RelayReader');
const RelayRecordSource = require('./RelayRecordSource');
const RelayRecordSourceMutator = require('../mutations/RelayRecordSourceMutator');
Expand Down Expand Up @@ -55,6 +54,10 @@ type PendingUpdater = {|
+updater: StoreUpdater,
|};

const applyWithGuard =
global.ErrorUtils?.applyWithGuard ??
((callback, context, args, onError, name) => callback.apply(context, args));

/**
* Coordinates the concurrent modification of a `Store` due to optimistic and
* non-revertable client updates and server payloads:
Expand Down Expand Up @@ -299,7 +302,7 @@ class RelayPublishQueue implements PublishQueue {
mutator,
this._getDataID,
);
ErrorUtils.applyWithGuard(
applyWithGuard(
updater,
null,
[recordSourceProxy],
Expand Down Expand Up @@ -334,7 +337,7 @@ class RelayPublishQueue implements PublishQueue {
const processUpdate = optimisticUpdate => {
if (optimisticUpdate.storeUpdater) {
const {storeUpdater} = optimisticUpdate;
ErrorUtils.applyWithGuard(
applyWithGuard(
storeUpdater,
null,
[recordSourceProxy],
Expand All @@ -355,7 +358,7 @@ class RelayPublishQueue implements PublishQueue {
selectorData = lookupSelector(source, operation.fragment);
}
if (updater) {
ErrorUtils.applyWithGuard(
applyWithGuard(
updater,
null,
[recordSourceSelectorProxy, selectorData],
Expand Down
13 changes: 7 additions & 6 deletions packages/relay-runtime/store/__tests__/RelayPublishQueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

'use strict';

const ErrorUtils = require('ErrorUtils');
const RelayModernRecord = require('../RelayModernRecord');
const RelayModernStore = require('../RelayModernStore');
const RelayPublishQueue = require('../RelayPublishQueue');
Expand Down Expand Up @@ -39,11 +38,13 @@ describe('RelayPublishQueue', () => {
beforeEach(() => {
jest.resetModules();

ErrorUtils.applyWithGuard = jest.fn((callback, context, params) => {
try {
callback.apply(context, params);
} catch (guarded) {} // eslint-disable-line lint/no-unused-catch-bindings
});
global.ErrorUtils = {
applyWithGuard: jest.fn((callback, context, params) => {
try {
callback.apply(context, params);
} catch (guarded) {} // eslint-disable-line lint/no-unused-catch-bindings
}),
};
});

describe('applyUpdate()/revertUpdate()', () => {
Expand Down
1 change: 0 additions & 1 deletion scripts/getBabelOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = function(options) {
require('./rewrite-modules'),
{
map: {
ErrorUtils: 'fbjs/lib/ErrorUtils',
Promise: 'promise-polyfill',
areEqual: 'fbjs/lib/areEqual',
invariant: 'fbjs/lib/invariant',
Expand Down

0 comments on commit 5ed076e

Please sign in to comment.