@samitouri / QOS-React-2 / commits / 04e341936c

Include Object.assign polyfill

This isn't a good final solution but it makes React actually usable on its own. This also makes tests runnable, though only via jest (./node_modules/.bin/jest)

Paul O’Shannessy committed Jul 21, 2014 at 16:18 UTC 04e341936cff902f399ca59bd6b855b2d994470e
3 files changed +59
jest/environment.js
+2
@@ -1 +1,3 @@
1 __DEV__ = true;
2 +
3 +require.requireActual('../src/vendor/polyfill/Object.es6.js');
src/browser/ui/React.js
+4
@@ -18,6 +18,10 @@
18
19 "use strict";
20
21 +// TODO: Move this elsewhere - it only exists in open source until a better
22 +// solution is found.
23 +require('Object.es6');
24 +
25 var DOMPropertyOperations = require('DOMPropertyOperations');
26 var EventPluginUtils = require('EventPluginUtils');
27 var ReactChildren = require('ReactChildren');
src/vendor/polyfill/Object.es6.js new
+53
@@ -0,0 +1,53 @@
1 +/**
2 + * Copyright 2014 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 Object.es6
17 + * @polyfill
18 + */
19 +
20 +// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign
21 +
22 +if (!Object.assign) {
23 + Object.assign = function(target, sources) {
24 + if (target == null) {
25 + throw new TypeError('Object.assign target cannot be null or undefined');
26 + }
27 + var to = Object(target);
28 +
29 + var hasOwnProperty = Object.prototype.hasOwnProperty;
30 +
31 + for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
32 + var nextSource = arguments[nextIndex];
33 + if (nextSource == null) {
34 + throw new TypeError('Object.assign source cannot be null or undefined');
35 + }
36 +
37 + var from = Object(nextSource);
38 +
39 + // We don't currently support accessors nor proxies. Therefore this copy
40 + // cannot throw. If we ever supported this then we must handle
41 + // exceptions and side-effects.
42 +
43 + for (var key in from) {
44 + if (hasOwnProperty.call(from, key)) {
45 + to[key] = from[key];
46 + }
47 + }
48 + }
49 +
50 + return to;
51 + };
52 +}
53 +