@samitouri / QOS-React-2 / commits / 8ab0ecba13

Sync internal modules

We've actually diverged more with some modules, but we don't want a cascade of dependencies out here. Mostly, the changes internally that we don't want are tied to FB infrastructure but otherwise are functionally equivalent (usually around error reporting, code monitoring).

Paul O’Shannessy committed Feb 5, 2015 at 16:31 UTC 8ab0ecba137ba030edea84cd19fc1bfaf0f071b8
6 files changed +9 -415
src/vendor/core/createArrayFromMixed.js renamed
+5 -5
@@ -6,7 +6,7 @@
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 createArrayFrom
9 + * @providesModule createArrayFromMixed
10 * @typechecks
11 */
12
@@ -57,10 +57,10 @@ function hasArrayNature(obj) {
57 *
58 * This is mostly useful idiomatically:
59 *
60 - * var createArrayFrom = require('createArrayFrom');
60 + * var createArrayFromMixed = require('createArrayFromMixed');
61 *
62 * function takesOneOrMoreThings(things) {
63 - * things = createArrayFrom(things);
63 + * things = createArrayFromMixed(things);
64 * ...
65 * }
66 *
@@ -72,7 +72,7 @@ function hasArrayNature(obj) {
72 * @param {*} obj
73 * @return {array}
74 */
75 -function createArrayFrom(obj) {
75 +function createArrayFromMixed(obj) {
76 if (!hasArrayNature(obj)) {
77 return [obj];
78 } else if (Array.isArray(obj)) {
@@ -82,4 +82,4 @@ function createArrayFrom(obj) {
82 }
83 }
84
85 -module.exports = createArrayFrom;
85 +module.exports = createArrayFromMixed;
src/vendor/core/createNodesFromMarkup.js
+3 -3
@@ -14,7 +14,7 @@
14
15 var ExecutionEnvironment = require('ExecutionEnvironment');
16
17 -var createArrayFrom = require('createArrayFrom');
17 +var createArrayFromMixed = require('createArrayFromMixed');
18 var getMarkupWrap = require('getMarkupWrap');
19 var invariant = require('invariant');
20
@@ -73,10 +73,10 @@ function createNodesFromMarkup(markup, handleScript) {
73 handleScript,
74 'createNodesFromMarkup(...): Unexpected <script> element rendered.'
75 );
76 - createArrayFrom(scripts).forEach(handleScript);
76 + createArrayFromMixed(scripts).forEach(handleScript);
77 }
78
79 - var nodes = createArrayFrom(node.childNodes);
79 + var nodes = createArrayFromMixed(node.childNodes);
80 while (node.lastChild) {
81 node.removeChild(node.lastChild);
82 }
src/vendor/core/mergeDeep.js deleted
-46
@@ -1,46 +0,0 @@
1 -/**
2 - * Copyright 2013-2015, 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 mergeDeep
10 - */
11 -
12 -"use strict";
13 -
14 -var mergeHelpers = require('mergeHelpers');
15 -var mergeDeepInto = require('mergeDeepInto');
16 -
17 -var checkArrayStrategy = mergeHelpers.checkArrayStrategy;
18 -var checkMergeObjectArgs = mergeHelpers.checkMergeObjectArgs;
19 -var normalizeMergeArg = mergeHelpers.normalizeMergeArg;
20 -
21 -/**
22 - * @see mergeDeepImpl comments.
23 - *
24 - * @param {!Object} one returned will be an structural extension of this.
25 - * @param {!Object} two values from two take precedence over values in one.
26 - * @param {?Enum=} arrayStrategy One of `arrayStrategies`.
27 - * @return {!Object} the extension of one by two.
28 - */
29 -var mergeDeep = function(oneParam, twoParam, arrayStrategy) {
30 - var one = normalizeMergeArg(oneParam);
31 - var two = normalizeMergeArg(twoParam);
32 - checkMergeObjectArgs(one, two);
33 - checkArrayStrategy(arrayStrategy);
34 - var newObj = {};
35 - // TODO: This is horribly inefficient. Even when some deep object in `one`
36 - // will be clobbered by another entity in `two`, we perform a clone of that
37 - // entire structure. To make this code more efficient, we'll need to either
38 - // enhance `mergeDeepInto` to accept multiple arguments or mirror that code
39 - // here.
40 - mergeDeepInto(newObj, one, arrayStrategy);
41 - mergeDeepInto(newObj, two, arrayStrategy);
42 - return newObj;
43 -};
44 -
45 -
46 -module.exports = mergeDeep;
src/vendor/core/mergeDeepInto.js deleted
-220
@@ -1,220 +0,0 @@
1 -/**
2 - * Copyright 2013-2015, 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 mergeDeepInto
10 - */
11 -
12 -// Empty blocks improve readability so disable that warning
13 -// jshint -W035
14 -
15 -"use strict";
16 -
17 -var invariant = require('invariant');
18 -var mergeHelpers = require('mergeHelpers');
19 -
20 -var ArrayStrategies = mergeHelpers.ArrayStrategies;
21 -var checkArrayStrategy = mergeHelpers.checkArrayStrategy;
22 -var checkMergeArrayArgs = mergeHelpers.checkMergeArrayArgs;
23 -var checkMergeLevel = mergeHelpers.checkMergeLevel;
24 -var checkMergeObjectArgs = mergeHelpers.checkMergeObjectArgs;
25 -var isTerminal = mergeHelpers.isTerminal;
26 -var normalizeMergeArg = mergeHelpers.normalizeMergeArg;
27 -
28 -/**
29 - * Every deep merge function must handle merging in each of the following cases
30 - * at every level. We may refer to letters below in implementations. For each
31 - * case listed, the "Result" listed describes the *value* of the result, but
32 - * does not specify anything about the memory graph of the result. In other
33 - * words the Results listed below will be the same for `merge` and `mergeInto`
34 - * but `merge` may have different guarantees about mutation/cloning. In the
35 - * table, "Object" refers to a non- Array, non-terminal object. One result is
36 - * undefined and requires that the caller specify the resolution policy (only
37 - * when trying to merge two arrays).
38 - *
39 - * Scenario Result
40 - * --------------------------------------------------------------
41 - * [A]: (terminal, terminal) right terminal
42 - * [B]: (terminal, Array) right Array
43 - * [C]: (terminal, Object) right Object
44 - * [D]: (terminal, not present) left terminal
45 - * [E]: (Array, terminal) right terminal
46 - * [F]: (Array, Array) UNDEFINED - MUST SPECIFY POLICY
47 - * [G]: (Array, Object) right Object
48 - * [H]: (Array, not present) left Array
49 - * [I]: (Object, terminal) right terminal
50 - * [J]: (Object, Array) right Array
51 - * [K]: (Object, Object) merge of left and right Objects
52 - * [L]: (Object, not present) left Object
53 - * [M]: (not present, terminal) right terminal
54 - * [N]: (not present, Array) right Array
55 - * [O]: (not present, Object) right Object
56 - *
57 - * All merge functions are only expected to reason about "own" properties and,
58 - * any prototypical properties should have no effect on the result. At the first
59 - * level of recursion in deep merges, we may choose to normalize arguments
60 - * (convert undefined to empty objects etc.) The above chart does not describe
61 - * the result of those top level operations which behave specially due to the
62 - * normalization.
63 - */
64 -
65 -/**
66 - * Deep merge implementation for non-Array, non-terminal Objects.
67 - *
68 - * @param {!Object} one non-Array, non-terminal Object to be mutated deeply.
69 - * @param {!Object} two non-Array, non-terminal taking precedence over `one`.
70 - * @param {?Enum=} arrayStrategy one of `arrayStrategies`.
71 - * @param {!number} level The level of recursion.
72 - */
73 -var mergeDeepIntoObjects = function(one, two, arrayStrategy, level) {
74 - checkMergeObjectArgs(one, two);
75 - checkMergeLevel(level);
76 - var twoKeys = two ? Object.keys(two) : [];
77 - for (var i = 0; i < twoKeys.length; i++) {
78 - var twoKey = twoKeys[i];
79 - mergeSingleFieldDeep(one, two, twoKey, arrayStrategy, level);
80 - }
81 -};
82 -
83 -/**
84 - * Deep merge implementation for Arrays.
85 - *
86 - * @param {!Array} one Array to deep merge.
87 - * @param {!Array} two Array to deep merge "into" `one`.
88 - * @param {?Enum=} arrayStrategy one of `arrayStrategies`.
89 - * @param {!number} level Level of recursion.
90 - */
91 -var mergeDeepIntoArrays = function(one, two, arrayStrategy, level) {
92 - checkMergeArrayArgs(one, two);
93 - checkMergeLevel(level);
94 -
95 - var maxLen = Math.max(one.length, two.length);
96 - for (var i = 0; i < maxLen; i++) {
97 - mergeSingleFieldDeep(one, two, i, arrayStrategy, level);
98 - }
99 -};
100 -
101 -/**
102 - * Given two truthy containers `one` and `two`, and a `key`, performs a deep
103 - * merge on a logical field.
104 - *
105 - * @param {!Array|Object} one Container to merge into.
106 - * @param {!Array|Object} two Container to merge from.
107 - * @param {!string} key Key of field that should be merged.
108 - * @param {lEnum=} arrayStrategy One of `arrayStrategies`.
109 - * @param {!number} level Current level of recursion.
110 - */
111 -var mergeSingleFieldDeep = function(one, two, key, arrayStrategy, level) {
112 - var twoVal = two[key];
113 - var twoValIsPresent = two.hasOwnProperty(key);
114 - var twoValIsTerminal = twoValIsPresent && isTerminal(twoVal);
115 - var twoValIsArray = twoValIsPresent && Array.isArray(twoVal);
116 - var twoValIsProperObject =
117 - twoValIsPresent && !twoValIsArray && !twoValIsArray;
118 -
119 - var oneVal = one[key];
120 - var oneValIsPresent = one.hasOwnProperty(key);
121 - var oneValIsTerminal = oneValIsPresent && isTerminal(oneVal);
122 - var oneValIsArray = oneValIsPresent && Array.isArray(oneVal);
123 - var oneValIsProperObject =
124 - oneValIsPresent && !oneValIsArray && !oneValIsArray;
125 -
126 - if (oneValIsTerminal) {
127 - if (twoValIsTerminal) { // [A]
128 - one[key] = twoVal;
129 - } else if (twoValIsArray) { // [B]
130 - one[key] = [];
131 - mergeDeepIntoArrays(one[key], twoVal, arrayStrategy, level + 1);
132 - } else if (twoValIsProperObject) { // [C]
133 - one[key] = {};
134 - mergeDeepIntoObjects(one[key], twoVal, arrayStrategy, level + 1);
135 - } else if (!twoValIsPresent) { // [D]
136 - one[key] = oneVal;
137 - }
138 - } else if (oneValIsArray) {
139 - if (twoValIsTerminal) { // [E]
140 - one[key] = twoVal;
141 - } else if (twoValIsArray) { // [F]
142 - invariant(
143 - ArrayStrategies[arrayStrategy],
144 - 'mergeDeepInto(...): Attempted to merge two arrays, but a valid ' +
145 - 'ArrayStrategy was not specified.'
146 - );
147 - // Else: At this point, the only other valid option is `IndexByIndex`
148 - if (arrayStrategy === ArrayStrategies.Clobber) {
149 - oneVal.length = 0;
150 - }
151 - mergeDeepIntoArrays(oneVal, twoVal, arrayStrategy, level + 1);
152 - } else if (twoValIsProperObject) { // [G]
153 - one[key] = {};
154 - mergeDeepIntoObjects(one[key], twoVal, arrayStrategy, level + 1);
155 - } else if (!twoValIsPresent) { // [H]
156 - // Leave the left Array alone
157 - }
158 - } else if (oneValIsProperObject) {
159 - if (twoValIsTerminal) { // [I]
160 - one[key] = twoVal;
161 - } else if (twoValIsArray) { // [J]
162 - one[key] = [];
163 - mergeDeepIntoArrays(one[key], twoVal, arrayStrategy, level + 1);
164 - } else if (twoValIsProperObject) { // [K]
165 - mergeDeepIntoObjects(oneVal, twoVal, arrayStrategy, level + 1);
166 - } else if (!twoValIsPresent) { // [L]
167 - // Leave the left Object alone
168 - }
169 - } else if (!oneValIsPresent) {
170 - if (twoValIsTerminal) { // [M]
171 - one[key] = twoVal;
172 - } else if (twoValIsArray) { // [N]
173 - one[key] = [];
174 - mergeDeepIntoArrays(one[key], twoVal, arrayStrategy, level + 1);
175 - } else if (twoValIsProperObject) { // [O]
176 - one[key] = {};
177 - mergeDeepIntoObjects(one[key], twoVal, arrayStrategy, level + 1);
178 - } else if (!twoValIsPresent) {
179 - // Could/should never happen
180 - }
181 - }
182 -};
183 -
184 -
185 -
186 -/**
187 - * Provides same functionality as mergeInto, but merges by mutating the first
188 - * argument. Will never mutate the second argument.
189 - *
190 - * mergeDeepInto provides two guarantees:
191 - * 1. In the process of mutating one, will not mutate two.
192 - * 2. Will not cause any nonTerminal memory to be shared between one and two.
193 - * This means that no further mutations to one will effect two (unless some
194 - * other part of your application forms shared memory between one and two).
195 - *
196 - * mergeDeepInto does not guarantee that it will *preserve* any shared memory
197 - * between two and one that existed before invocation. After calling
198 - * mergeDeepInto, there will be less (or equal) amount of shared memory between
199 - * one and two.
200 - *
201 - * Will tolerate a circular structure as the first parameter, but not the
202 - * second.
203 - *
204 - * Requires that first parameter be a non-Array, non-terminal `Object`, and the
205 - * second argument either be an `Object` or `null/undefined`. Arrays may exist
206 - * in the depths of either `Object` as long as an `arrayStrategy` is supplied.
207 - *
208 - * The third parameter indicates how merging two `Array`s should be performed.
209 - *
210 - * @param {!Object} one Object to be mutated deeply.
211 - * @param {?Object} two Values from two take precedence over values in one.
212 - * @param {?Enum=} arrayStrategy One of arrayStrategy
213 - */
214 -var mergeDeepInto = function(one, twoParam, arrayStrategy) {
215 - var two = normalizeMergeArg(twoParam);
216 - checkArrayStrategy(arrayStrategy); // Will be checked twice, for now.
217 - mergeDeepIntoObjects(one, two, arrayStrategy, 0);
218 -};
219 -
220 -module.exports = mergeDeepInto;
src/vendor/core/mergeHelpers.js deleted
-140
@@ -1,140 +0,0 @@
1 -/**
2 - * Copyright 2013-2015, 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 mergeHelpers
10 - *
11 - * requiresPolyfills: Array.isArray
12 - */
13 -
14 -"use strict";
15 -
16 -var invariant = require('invariant');
17 -var keyMirror = require('keyMirror');
18 -
19 -/**
20 - * Maximum number of levels to traverse. Will catch circular structures.
21 - * @const
22 - */
23 -var MAX_MERGE_DEPTH = 36;
24 -
25 -/**
26 - * We won't worry about edge cases like new String('x') or new Boolean(true).
27 - * Functions are considered terminals, and arrays are not.
28 - * @param {*} o The item/object/value to test.
29 - * @return {boolean} true iff the argument is a terminal.
30 - */
31 -var isTerminal = function(o) {
32 - return typeof o !== 'object' || o === null;
33 -};
34 -
35 -var mergeHelpers = {
36 -
37 - MAX_MERGE_DEPTH: MAX_MERGE_DEPTH,
38 -
39 - isTerminal: isTerminal,
40 -
41 - /**
42 - * Converts null/undefined values into empty object.
43 - *
44 - * @param {?Object=} arg Argument to be normalized (nullable optional)
45 - * @return {!Object}
46 - */
47 - normalizeMergeArg: function(arg) {
48 - return arg === undefined || arg === null ? {} : arg;
49 - },
50 -
51 - /**
52 - * If merging Arrays, a merge strategy *must* be supplied. If not, it is
53 - * likely the caller's fault. If this function is ever called with anything
54 - * but `one` and `two` being `Array`s, it is the fault of the merge utilities.
55 - *
56 - * @param {*} one Array to merge into.
57 - * @param {*} two Array to merge from.
58 - */
59 - checkMergeArrayArgs: function(one, two) {
60 - invariant(
61 - Array.isArray(one) && Array.isArray(two),
62 - 'Tried to merge arrays, instead got %s and %s.',
63 - one,
64 - two
65 - );
66 - },
67 -
68 - /**
69 - * @param {*} one Object to merge into.
70 - * @param {*} two Object to merge from.
71 - */
72 - checkMergeObjectArgs: function(one, two) {
73 - mergeHelpers.checkMergeObjectArg(one);
74 - mergeHelpers.checkMergeObjectArg(two);
75 - },
76 -
77 - /**
78 - * @param {*} arg
79 - */
80 - checkMergeObjectArg: function(arg) {
81 - invariant(
82 - !isTerminal(arg) && !Array.isArray(arg),
83 - 'Tried to merge an object, instead got %s.',
84 - arg
85 - );
86 - },
87 -
88 - /**
89 - * @param {*} arg
90 - */
91 - checkMergeIntoObjectArg: function(arg) {
92 - invariant(
93 - (!isTerminal(arg) || typeof arg === 'function') && !Array.isArray(arg),
94 - 'Tried to merge into an object, instead got %s.',
95 - arg
96 - );
97 - },
98 -
99 - /**
100 - * Checks that a merge was not given a circular object or an object that had
101 - * too great of depth.
102 - *
103 - * @param {number} Level of recursion to validate against maximum.
104 - */
105 - checkMergeLevel: function(level) {
106 - invariant(
107 - level < MAX_MERGE_DEPTH,
108 - 'Maximum deep merge depth exceeded. You may be attempting to merge ' +
109 - 'circular structures in an unsupported way.'
110 - );
111 - },
112 -
113 - /**
114 - * Checks that the supplied merge strategy is valid.
115 - *
116 - * @param {string} Array merge strategy.
117 - */
118 - checkArrayStrategy: function(strategy) {
119 - invariant(
120 - strategy === undefined || strategy in mergeHelpers.ArrayStrategies,
121 - 'You must provide an array strategy to deep merge functions to ' +
122 - 'instruct the deep merge how to resolve merging two arrays.'
123 - );
124 - },
125 -
126 - /**
127 - * Set of possible behaviors of merge algorithms when encountering two Arrays
128 - * that must be merged together.
129 - * - `clobber`: The left `Array` is ignored.
130 - * - `indexByIndex`: The result is achieved by recursively deep merging at
131 - * each index. (not yet supported.)
132 - */
133 - ArrayStrategies: keyMirror({
134 - Clobber: true,
135 - IndexByIndex: true
136 - })
137 -
138 -};
139 -
140 -module.exports = mergeHelpers;
src/vendor/core/toArray.js
+1 -1
@@ -16,7 +16,7 @@ var invariant = require('invariant');
16 * Convert array-like objects to arrays.
17 *
18 * This API assumes the caller knows the contents of the data type. For less
19 - * well defined inputs use createArrayFrom.
19 + * well defined inputs use createArrayFromMixed.
20 *
21 * @param {object|function|filelist} obj
22 * @return {array}