Skip to content

Commit 77b04f3

Browse files
gabrielbullskevy
authored andcommitted
Removed dependency on fbjs (react-navigation#1698)
1 parent 48b09bf commit 77b04f3

14 files changed

+147
-13
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
},
7777
"dependencies": {
7878
"clamp": "^1.0.1",
79-
"fbjs": "^0.8.12",
8079
"hoist-non-react-statics": "^1.2.0",
8180
"path-to-regexp": "^1.7.0",
8281
"prop-types": "^15.5.10",

src/StateUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import invariant from 'fbjs/lib/invariant';
3+
import invariant from './utils/invariant';
44

55
import type { NavigationRoute, NavigationState } from './TypeDefinition';
66

src/createNavigationContainer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import React from 'react';
4-
import invariant from 'fbjs/lib/invariant';
4+
import invariant from './utils/invariant';
55
import { BackAndroid, Linking } from './PlatformHelpers';
66
import NavigationActions from './NavigationActions';
77
import addNavigationHelpers from './addNavigationHelpers';

src/routers/TabRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import invariant from 'fbjs/lib/invariant';
3+
import invariant from '../utils/invariant';
44
import getScreenForRouteName from './getScreenForRouteName';
55
import createConfigGetter from './createConfigGetter';
66

src/routers/createConfigGetter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @flow
33
*/
44

5-
import invariant from 'fbjs/lib/invariant';
5+
import invariant from '../utils/invariant';
66

77
import getScreenForRouteName from './getScreenForRouteName';
88
import addNavigationHelpers from '../addNavigationHelpers';

src/routers/getScreenConfigDeprecated.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @flow
33
*/
4-
import invariant from 'fbjs/lib/invariant';
4+
import invariant from '../utils/invariant';
55

66
export default () =>
77
invariant(

src/routers/getScreenForRouteName.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import invariant from 'fbjs/lib/invariant';
3+
import invariant from '../utils/invariant';
44

55
import type {
66
NavigationComponent,

src/routers/validateRouteConfigMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @flow */
22

3-
import invariant from 'fbjs/lib/invariant';
3+
import invariant from '../utils/invariant';
44

55
import type { NavigationRouteConfigMap } from '../TypeDefinition';
66

src/routers/validateScreenOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* @flow */
2-
import invariant from 'fbjs/lib/invariant';
2+
import invariant from '../utils/invariant';
33

44
import type { NavigationRoute } from '../TypeDefinition';
55

src/utils/invariant.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule invariant
10+
*/
11+
12+
'use strict';
13+
14+
/**
15+
* Use invariant() to assert state which your program assumes to be true.
16+
*
17+
* Provide sprintf-style format (only %s is supported) and arguments
18+
* to provide information about what broke and what you were
19+
* expecting.
20+
*
21+
* The invariant message will be stripped in production, but the invariant
22+
* will remain to ensure logic does not differ in production.
23+
*/
24+
25+
var validateFormat = function(format) {};
26+
27+
if (__DEV__) {
28+
validateFormat = function(format) {
29+
if (format === undefined) {
30+
throw new Error('invariant requires an error message argument');
31+
}
32+
};
33+
}
34+
35+
function invariant(condition, format, a, b, c, d, e, f) {
36+
validateFormat(format);
37+
38+
if (!condition) {
39+
var error;
40+
if (format === undefined) {
41+
error = new Error(
42+
'Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.'
43+
);
44+
} else {
45+
var args = [a, b, c, d, e, f];
46+
var argIndex = 0;
47+
error = new Error(
48+
format.replace(/%s/g, function() {
49+
return args[argIndex++];
50+
})
51+
);
52+
error.name = 'Invariant Violation';
53+
}
54+
55+
error.framesToPop = 1; // we don't care about invariant's own frame
56+
throw error;
57+
}
58+
}
59+
60+
module.exports = invariant;

src/utils/shallowEqual.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule shallowEqual
10+
* @typechecks
11+
* @flow
12+
*/
13+
14+
/*eslint-disable no-self-compare */
15+
16+
'use strict';
17+
18+
const hasOwnProperty = Object.prototype.hasOwnProperty;
19+
20+
/**
21+
* inlined Object.is polyfill to avoid requiring consumers ship their own
22+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
23+
*/
24+
function is(x: mixed, y: mixed): boolean {
25+
// SameValue algorithm
26+
if (x === y) {
27+
// Steps 1-5, 7-10
28+
// Steps 6.b-6.e: +0 != -0
29+
// Added the nonzero y check to make Flow happy, but it is redundant
30+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
31+
} else {
32+
// Step 6.a: NaN == NaN
33+
return x !== x && y !== y;
34+
}
35+
}
36+
37+
/**
38+
* Performs equality by iterating through keys on an object and returning false
39+
* when any key has values which are not strictly equal between the arguments.
40+
* Returns true when the values of all keys are strictly equal.
41+
*/
42+
function shallowEqual(objA: mixed, objB: mixed): boolean {
43+
if (is(objA, objB)) {
44+
return true;
45+
}
46+
if (
47+
typeof objA !== 'object' ||
48+
objA === null ||
49+
typeof objB !== 'object' ||
50+
objB === null
51+
) {
52+
return false;
53+
}
54+
55+
const keysA = Object.keys(objA);
56+
const keysB = Object.keys(objB);
57+
58+
if (keysA.length !== keysB.length) {
59+
return false;
60+
}
61+
62+
// Test for A's keys different from B.
63+
for (let i = 0; i < keysA.length; i++) {
64+
if (
65+
!hasOwnProperty.call(objB, keysA[i]) ||
66+
!is(objA[keysA[i]], objB[keysA[i]])
67+
) {
68+
return false;
69+
}
70+
}
71+
72+
return true;
73+
}
74+
75+
module.exports = shallowEqual;

src/views/PointerEventsContainer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React from 'react';
44

5-
import invariant from 'fbjs/lib/invariant';
5+
import invariant from '../utils/invariant';
66

77
import AnimatedValueSubscription from './AnimatedValueSubscription';
88

src/views/ScenesReducer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

3-
import invariant from 'fbjs/lib/invariant';
4-
import shallowEqual from 'fbjs/lib/shallowEqual';
3+
import invariant from '../utils/invariant';
4+
import shallowEqual from '../utils/shallowEqual';
55

66
import type {
77
NavigationRoute,

src/views/Transitioner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44

55
import { Animated, StyleSheet, View } from 'react-native';
66

7-
import invariant from 'fbjs/lib/invariant';
7+
import invariant from '../utils/invariant';
88

99
import NavigationScenesReducer from './ScenesReducer';
1010
import TransitionConfigs from './TransitionConfigs';

0 commit comments

Comments
 (0)