Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to make React elements immutable #120

Merged
merged 8 commits into from
Apr 19, 2016
Merged
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"mocha": "2.4.5",
"mocha-istanbul": "0.2.0",
"mocha-lcov-reporter": "1.2.0",
"react": "^15.0.1",
"zuul": "3.9.0"
},
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion seamless-immutable.development.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
(function() {
"use strict";

// https://github.com/facebook/react/blob/v15.0.1/src/isomorphic/classic/element/ReactElement.js#L21
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element');
var REACT_ELEMENT_TYPE_FALLBACK = 0xeac7;

function addPropertyTo(target, methodName, value) {
Object.defineProperty(target, methodName, {
enumerable: false,
Expand Down Expand Up @@ -497,8 +501,16 @@
return makeImmutable(obj, mutatingObjectMethods);
}

// Returns true if object is a valid react element
// https://github.com/facebook/react/blob/v15.0.1/src/isomorphic/classic/element/ReactElement.js#L326
function isReactElement(obj) {
return typeof obj === 'object' &&
obj !== null &&
(obj.$$typeof === REACT_ELEMENT_TYPE_FALLBACK || obj.$$typeof === REACT_ELEMENT_TYPE);
}

function Immutable(obj, options, stackRemaining) {
if (isImmutable(obj)) {
if (isImmutable(obj) || isReactElement(obj)) {
return obj;
} else if (obj instanceof Array) {
return makeImmutableArray(obj.slice());
Expand Down
2 changes: 1 addition & 1 deletion seamless-immutable.development.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading