Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 45238bf

Browse files
author
Richard Feldman
committed
Merge pull request #120 from davidblurton/master
Don't try to make React elements immutable
2 parents 1c945eb + 784d648 commit 45238bf

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"mocha": "2.4.5",
1717
"mocha-istanbul": "0.2.0",
1818
"mocha-lcov-reporter": "1.2.0",
19+
"react": "^15.0.1",
1920
"zuul": "3.9.0"
2021
},
2122
"scripts": {

seamless-immutable.development.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
(function() {
22
"use strict";
33

4+
// https://github.com/facebook/react/blob/v15.0.1/src/isomorphic/classic/element/ReactElement.js#L21
5+
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element');
6+
var REACT_ELEMENT_TYPE_FALLBACK = 0xeac7;
7+
48
function addPropertyTo(target, methodName, value) {
59
Object.defineProperty(target, methodName, {
610
enumerable: false,
@@ -497,8 +501,16 @@
497501
return makeImmutable(obj, mutatingObjectMethods);
498502
}
499503

504+
// Returns true if object is a valid react element
505+
// https://github.com/facebook/react/blob/v15.0.1/src/isomorphic/classic/element/ReactElement.js#L326
506+
function isReactElement(obj) {
507+
return typeof obj === 'object' &&
508+
obj !== null &&
509+
(obj.$$typeof === REACT_ELEMENT_TYPE_FALLBACK || obj.$$typeof === REACT_ELEMENT_TYPE);
510+
}
511+
500512
function Immutable(obj, options, stackRemaining) {
501-
if (isImmutable(obj)) {
513+
if (isImmutable(obj) || isReactElement(obj)) {
502514
return obj;
503515
} else if (obj instanceof Array) {
504516
return makeImmutableArray(obj.slice());

seamless-immutable.development.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)