@samitouri / QOS-React-2 / commits / d9511d817a

Move utils out of React that aren't being used

Many of React's util functions are non-redundant with Facebook's core libraries, so move them out of React into a central location (out of this repo). These files were not getting used by any part of React core, so didn't actually belong here anyway.

James Ide committed Aug 16, 2013 at 14:52 UTC d9511d817a3cb10127d7eb88f3b5d42e1c3d4ae8
7 files changed -402
src/utils/__tests__/objFilter-test.js deleted
-88
@@ -1,88 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @emails react-core
17 - */
18 -
19 -"use strict";
20 -
21 -var objFilter = require('objFilter');
22 -
23 -describe('objFilter', function() {
24 -
25 - var obj = {
26 - A: 'apple',
27 - B: 'banana',
28 - C: 'coconut',
29 - D: 'durian',
30 - E: 'elderberry',
31 - F: 'fig',
32 - G: 'guava',
33 - H: 'hackberry'
34 - };
35 -
36 - it('should accept null', function() {
37 - var filtered = objFilter(null, function() {});
38 - expect(filtered).toBe(null);
39 - });
40 -
41 - it('should return true to create copy', function() {
42 - var filtered = objFilter(obj, function() {
43 - return true;
44 - });
45 - expect(filtered).not.toBe(obj);
46 - expect(filtered).toEqual(obj);
47 - });
48 -
49 - it('should return empty object for a falsey func', function() {
50 - var filtered = objFilter(obj, function() {
51 - return false;
52 - });
53 - expect(filtered).toEqual({});
54 - });
55 -
56 - it('should filter based on value', function() {
57 - var filtered = objFilter(obj, function(value) {
58 - return value.indexOf('berry') !== -1;
59 - });
60 - expect(filtered).toEqual({
61 - E: 'elderberry',
62 - H: 'hackberry'
63 - });
64 - });
65 -
66 - it('should filter based on key', function() {
67 - var filtered = objFilter(obj, function(value, key) {
68 - return (/[AEIOU]/).test(key);
69 - });
70 - expect(filtered).toEqual({
71 - A: 'apple',
72 - E: 'elderberry'
73 - });
74 - });
75 -
76 - it('should filter based on iteration', function() {
77 - var filtered = objFilter(obj, function(value, key, iteration) {
78 - return iteration % 2;
79 - });
80 - expect(filtered).toEqual({
81 - B: 'banana',
82 - D: 'durian',
83 - F: 'fig',
84 - H: 'hackberry'
85 - });
86 - });
87 -
88 -});
src/utils/__tests__/objMap-test.js deleted
-113
@@ -1,113 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @emails react-core
17 - */
18 -
19 -"use strict";
20 -
21 -var objMap = require('objMap');
22 -
23 -describe('objMap', function() {
24 -
25 - var obj = {
26 - A: 'apple',
27 - B: 'banana',
28 - C: 'coconut',
29 - D: 'durian',
30 - E: 'elderberry',
31 - F: 'fig',
32 - G: 'guava',
33 - H: 'hackberry'
34 - };
35 -
36 - it('should accept null', function() {
37 - var mapped = objMap(null, function() {});
38 - expect(mapped).toBe(null);
39 - });
40 -
41 - it('should return value to create copy', function() {
42 - var mapped = objMap(obj, function(value) {
43 - return value;
44 - });
45 - expect(mapped).not.toBe(obj);
46 - expect(mapped).toEqual(obj);
47 - });
48 -
49 - it('should always retain keys', function() {
50 - var mapped = objMap(obj, function() {
51 - return null;
52 - });
53 - expect(mapped).toEqual({
54 - A: null,
55 - B: null,
56 - C: null,
57 - D: null,
58 - E: null,
59 - F: null,
60 - G: null,
61 - H: null
62 - });
63 - });
64 -
65 - it('should map values', function() {
66 - var mapped = objMap(obj, function (value) {
67 - return value.toUpperCase();
68 - });
69 - expect(mapped).toEqual({
70 - A: 'APPLE',
71 - B: 'BANANA',
72 - C: 'COCONUT',
73 - D: 'DURIAN',
74 - E: 'ELDERBERRY',
75 - F: 'FIG',
76 - G: 'GUAVA',
77 - H: 'HACKBERRY'
78 - });
79 - });
80 -
81 - it('should map keys', function() {
82 - var mapped = objMap(obj, function (value, key) {
83 - return key;
84 - });
85 - expect(mapped).toEqual({
86 - A: 'A',
87 - B: 'B',
88 - C: 'C',
89 - D: 'D',
90 - E: 'E',
91 - F: 'F',
92 - G: 'G',
93 - H: 'H'
94 - });
95 - });
96 -
97 - it('should map iterations', function() {
98 - var mapped = objMap(obj, function (value, key, iteration) {
99 - return iteration;
100 - });
101 - expect(mapped).toEqual({
102 - A: 0,
103 - B: 1,
104 - C: 2,
105 - D: 3,
106 - E: 4,
107 - F: 5,
108 - G: 6,
109 - H: 7
110 - });
111 - });
112 -
113 -});
src/utils/bindNoArgs.js deleted
-30
@@ -1,30 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @providesModule bindNoArgs
17 - */
18 -
19 -"use strict";
20 -
21 -var bindNoArgs = function (func, context) {
22 - if (!func) {
23 - return null;
24 - }
25 - return function () {
26 - return func.call(context);
27 - };
28 -};
29 -
30 -module.exports = bindNoArgs;
src/utils/curryOnly.js deleted
-37
@@ -1,37 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @providesModule curryOnly
17 - */
18 -
19 -"use strict";
20 -
21 -/**
22 - * When the function who's first parameter you are currying accepts only a
23 - * single argument, and you want to curry it, use this function for performance
24 - * reasons, as it will never access 'arguments'. It would be an interesting
25 - * project to detect at static analysis time, calls to F.curry that could be
26 - * transformed to one of the two optimized versions seen here.
27 - */
28 -var curryOnly = function(func, val, context) {
29 - if (!func) {
30 - return null;
31 - }
32 - return function() {
33 - return func.call(context, val);
34 - };
35 -};
36 -
37 -module.exports = curryOnly;
src/utils/eachKeyVal.js deleted
-39
@@ -1,39 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @providesModule eachKeyVal
17 - */
18 -
19 -"use strict";
20 -
21 -/**
22 - * Invokes fun for each own property in obj. Invokes `fun(key, val, obj, i)`.
23 - * @param {?Object} obj The object to iterate over.
24 - * @param {?Function} fun The function to invoke.
25 - * @param {?context=} context The context to call from.
26 - */
27 -function eachKeyVal(obj, fun, context) {
28 - if (!obj || !fun) {
29 - return;
30 - }
31 - // Object.keys only returns the "own" properties.
32 - var objKeys = Object.keys(obj);
33 - var i;
34 - for (i=0; i < objKeys.length; i++) {
35 - fun.call(context, objKeys[i], obj[objKeys[i]], obj, i);
36 - }
37 -}
38 -
39 -module.exports = eachKeyVal;
src/utils/objFilter.js deleted
-48
@@ -1,48 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @providesModule objFilter
17 - */
18 -
19 -"use strict";
20 -
21 -/**
22 - * For each key/value pair, invokes callback func and constructs a resulting
23 - * object which contains each key/value pair which produces a truthy result
24 - * from invoking the function:
25 - *
26 - * func(value, key, iteration)
27 - *
28 - * @param {?object} obj Object to map keys over
29 - * @param {function} func Invoked for each key/val pair.
30 - * @param {?*} context
31 - * @return {?object} Result of filtering or null if obj is falsey
32 - */
33 -function objFilter(obj, func, context) {
34 - if (!obj) {
35 - return null;
36 - }
37 - var i = 0;
38 - var ret = {};
39 - for (var key in obj) {
40 - if (obj.hasOwnProperty(key) &&
41 - func.call(context, obj[key], key, i++)) {
42 - ret[key] = obj[key];
43 - }
44 - }
45 - return ret;
46 -}
47 -
48 -module.exports = objFilter;
src/utils/objMap.js deleted
-47
@@ -1,47 +0,0 @@
1 -/**
2 - * Copyright 2013 Facebook, Inc.
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - *
16 - * @providesModule objMap
17 - */
18 -
19 -"use strict";
20 -
21 -/**
22 - * For each key/value pair, invokes callback func and constructs a resulting
23 - * object which contains, for every key in obj, values that are the result of
24 - * of invoking the function:
25 - *
26 - * func(value, key, iteration)
27 - *
28 - * @param {?object} obj Object to map keys over
29 - * @param {function} func Invoked for each key/val pair.
30 - * @param {?*} context
31 - * @return {?object} Result of mapping or null if obj is falsey
32 - */
33 -function objMap(obj, func, context) {
34 - if (!obj) {
35 - return null;
36 - }
37 - var i = 0;
38 - var ret = {};
39 - for (var key in obj) {
40 - if (obj.hasOwnProperty(key)) {
41 - ret[key] = func.call(context, obj[key], key, i++);
42 - }
43 - }
44 - return ret;
45 -}
46 -
47 -module.exports = objMap;