react-proxy
Advanced tools
Comparing version
@@ -63,12 +63,11 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function _interopRequire(obj) { return obj && obj.__esModule ? obj['default'] : obj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _createClassProxy = __webpack_require__(12); | ||
exports.createProxy = _interopRequire(_createClassProxy); | ||
var _createClassProxy2 = _interopRequireDefault(_createClassProxy); | ||
var _reactDeepForceUpdate = __webpack_require__(39); | ||
exports['default'] = _createClassProxy2['default']; | ||
module.exports = exports['default']; | ||
exports.getForceUpdate = _interopRequire(_reactDeepForceUpdate); | ||
/***/ }, | ||
@@ -544,11 +543,11 @@ /* 1 */ | ||
function proxyClass(InitialClass) { | ||
function proxyClass(InitialComponent) { | ||
// Prevent double wrapping. | ||
// Given a proxy class, return the existing proxy managing it. | ||
if (Object.prototype.hasOwnProperty.call(InitialClass, '__reactPatchProxy')) { | ||
return InitialClass.__reactPatchProxy; | ||
if (Object.prototype.hasOwnProperty.call(InitialComponent, '__reactPatchProxy')) { | ||
return InitialComponent.__reactPatchProxy; | ||
} | ||
var prototypeProxy = (0, _createPrototypeProxy2['default'])(); | ||
var CurrentClass = undefined; | ||
var CurrentComponent = undefined; | ||
var ProxyComponent = undefined; | ||
@@ -558,27 +557,30 @@ var staticDescriptors = {}; | ||
// Compare the descriptor with the one we previously set ourselves. | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(ProxyClass, key); | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key); | ||
return !isEqualDescriptor(staticDescriptors[key], currentDescriptor); | ||
} | ||
var ProxyClass = undefined; | ||
try { | ||
// Create a proxy constructor with matching name | ||
ProxyClass = new Function('getCurrentClass', 'return function ' + (InitialClass.name || 'ProxyClass') + '() {\n return getCurrentClass().apply(this, arguments);\n }')(function () { | ||
return CurrentClass; | ||
ProxyComponent = new Function('getCurrentComponent', 'return function ' + (InitialComponent.name || 'ProxyComponent') + '() {\n return getCurrentComponent().apply(this, arguments);\n }')(function () { | ||
return CurrentComponent; | ||
}); | ||
} catch (err) { | ||
// Some environments may forbid dynamic evaluation | ||
ProxyClass = function () { | ||
return CurrentClass.apply(this, arguments); | ||
ProxyComponent = function () { | ||
return CurrentComponent.apply(this, arguments); | ||
}; | ||
} | ||
// Point proxy constructor to the proxy prototype | ||
ProxyClass.prototype = prototypeProxy.get(); | ||
// Proxy toString() to the current constructor | ||
ProxyClass.toString = function toString() { | ||
return CurrentClass.toString(); | ||
ProxyComponent.toString = function toString() { | ||
return CurrentComponent.toString(); | ||
}; | ||
var prototypeProxy = undefined; | ||
if (InitialComponent.prototype && InitialComponent.prototype.isReactComponent) { | ||
// Point proxy constructor to the proxy prototype | ||
prototypeProxy = (0, _createPrototypeProxy2['default'])(); | ||
ProxyComponent.prototype = prototypeProxy.get(); | ||
} | ||
function update(_x) { | ||
@@ -588,7 +590,7 @@ var _again = true; | ||
_function: while (_again) { | ||
var NextClass = _x; | ||
var NextComponent = _x; | ||
mountedInstances = undefined; | ||
_again = false; | ||
if (typeof NextClass !== 'function') { | ||
if (typeof NextComponent !== 'function') { | ||
throw new Error('Expected a constructor.'); | ||
@@ -598,4 +600,4 @@ } | ||
// Prevent proxy cycles | ||
if (Object.prototype.hasOwnProperty.call(NextClass, '__reactPatchProxy')) { | ||
_x = NextClass.__reactPatchProxy.__getCurrent(); | ||
if (Object.prototype.hasOwnProperty.call(NextComponent, '__reactPatchProxy')) { | ||
_x = NextComponent.__reactPatchProxy.__getCurrent(); | ||
_again = true; | ||
@@ -606,15 +608,12 @@ continue _function; | ||
// Save the next constructor so we call it | ||
CurrentClass = NextClass; | ||
CurrentComponent = NextComponent; | ||
// Update the prototype proxy with new methods | ||
var mountedInstances = prototypeProxy.update(NextClass.prototype); | ||
// Try to infer displayName | ||
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name; | ||
// Set up the constructor property so accessing the statics work | ||
ProxyClass.prototype.constructor = ProxyClass; | ||
// Set up the same prototype for inherited statics | ||
ProxyClass.__proto__ = NextClass.__proto__; | ||
ProxyComponent.__proto__ = NextComponent.__proto__; | ||
// Copy static methods and properties | ||
Object.getOwnPropertyNames(NextClass).forEach(function (key) { | ||
Object.getOwnPropertyNames(NextComponent).forEach(function (key) { | ||
if (RESERVED_STATICS.indexOf(key) > -1) { | ||
@@ -624,3 +623,3 @@ return; | ||
var staticDescriptor = _extends({}, Object.getOwnPropertyDescriptor(NextClass, key), { | ||
var staticDescriptor = _extends({}, Object.getOwnPropertyDescriptor(NextComponent, key), { | ||
configurable: true | ||
@@ -631,3 +630,3 @@ }); | ||
if (!wasStaticModifiedByUser(key)) { | ||
Object.defineProperty(ProxyClass, key, staticDescriptor); | ||
Object.defineProperty(ProxyComponent, key, staticDescriptor); | ||
staticDescriptors[key] = staticDescriptor; | ||
@@ -638,3 +637,3 @@ } | ||
// Remove old static methods and properties | ||
Object.getOwnPropertyNames(ProxyClass).forEach(function (key) { | ||
Object.getOwnPropertyNames(ProxyComponent).forEach(function (key) { | ||
if (RESERVED_STATICS.indexOf(key) > -1) { | ||
@@ -645,3 +644,3 @@ return; | ||
// Skip statics that exist on the next class | ||
if (NextClass.hasOwnProperty(key)) { | ||
if (NextComponent.hasOwnProperty(key)) { | ||
return; | ||
@@ -651,3 +650,3 @@ } | ||
// Skip non-configurable statics | ||
var descriptor = Object.getOwnPropertyDescriptor(ProxyClass, key); | ||
var descriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key); | ||
if (descriptor && !descriptor.configurable) { | ||
@@ -659,3 +658,3 @@ return; | ||
if (!wasStaticModifiedByUser(key)) { | ||
delete ProxyClass[key]; | ||
delete ProxyComponent[key]; | ||
delete staticDescriptors[key]; | ||
@@ -665,11 +664,13 @@ } | ||
// Try to infer displayName | ||
ProxyClass.displayName = NextClass.displayName || NextClass.name; | ||
if (prototypeProxy) { | ||
// Update the prototype proxy with new methods | ||
var mountedInstances = prototypeProxy.update(NextComponent.prototype); | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(_bindAutoBindMethods2['default']); | ||
mountedInstances.forEach(_deleteUnknownAutoBindMethods2['default']); | ||
// Set up the constructor property so accessing the statics work | ||
ProxyComponent.prototype.constructor = ProxyComponent; | ||
// Let the user take care of redrawing | ||
return mountedInstances; | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(_bindAutoBindMethods2['default']); | ||
mountedInstances.forEach(_deleteUnknownAutoBindMethods2['default']); | ||
} | ||
} | ||
@@ -679,10 +680,10 @@ }; | ||
function get() { | ||
return ProxyClass; | ||
return ProxyComponent; | ||
} | ||
function getCurrent() { | ||
return CurrentClass; | ||
return CurrentComponent; | ||
} | ||
update(InitialClass); | ||
update(InitialComponent); | ||
@@ -698,3 +699,3 @@ var proxy = { get: get, update: update }; | ||
Object.defineProperty(ProxyClass, '__reactPatchProxy', { | ||
Object.defineProperty(ProxyComponent, '__reactPatchProxy', { | ||
configurable: false, | ||
@@ -1877,49 +1878,4 @@ writable: false, | ||
/***/ }, | ||
/* 39 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = getForceUpdate; | ||
function traverseRenderedChildren(internalInstance, callback, argument) { | ||
callback(internalInstance, argument); | ||
if (internalInstance._renderedComponent) { | ||
traverseRenderedChildren(internalInstance._renderedComponent, callback, argument); | ||
} else { | ||
for (var key in internalInstance._renderedChildren) { | ||
if (internalInstance._renderedChildren.hasOwnProperty(key)) { | ||
traverseRenderedChildren(internalInstance._renderedChildren[key], callback, argument); | ||
} | ||
} | ||
} | ||
} | ||
function setPendingForceUpdate(internalInstance) { | ||
if (internalInstance._pendingForceUpdate === false) { | ||
internalInstance._pendingForceUpdate = true; | ||
} | ||
} | ||
function forceUpdateIfPending(internalInstance, React) { | ||
if (internalInstance._pendingForceUpdate === true) { | ||
var publicInstance = internalInstance._instance; | ||
React.Component.prototype.forceUpdate.call(publicInstance); | ||
} | ||
} | ||
function getForceUpdate(React) { | ||
return function (instance) { | ||
var internalInstance = instance._reactInternalInstance; | ||
traverseRenderedChildren(internalInstance, setPendingForceUpdate); | ||
traverseRenderedChildren(internalInstance, forceUpdateIfPending, React); | ||
}; | ||
} | ||
module.exports = exports["default"]; | ||
/***/ } | ||
/******/ ]) | ||
}); |
@@ -42,11 +42,11 @@ 'use strict'; | ||
function proxyClass(InitialClass) { | ||
function proxyClass(InitialComponent) { | ||
// Prevent double wrapping. | ||
// Given a proxy class, return the existing proxy managing it. | ||
if (Object.prototype.hasOwnProperty.call(InitialClass, '__reactPatchProxy')) { | ||
return InitialClass.__reactPatchProxy; | ||
if (Object.prototype.hasOwnProperty.call(InitialComponent, '__reactPatchProxy')) { | ||
return InitialComponent.__reactPatchProxy; | ||
} | ||
var prototypeProxy = (0, _createPrototypeProxy2['default'])(); | ||
var CurrentClass = undefined; | ||
var CurrentComponent = undefined; | ||
var ProxyComponent = undefined; | ||
@@ -56,27 +56,30 @@ var staticDescriptors = {}; | ||
// Compare the descriptor with the one we previously set ourselves. | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(ProxyClass, key); | ||
var currentDescriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key); | ||
return !isEqualDescriptor(staticDescriptors[key], currentDescriptor); | ||
} | ||
var ProxyClass = undefined; | ||
try { | ||
// Create a proxy constructor with matching name | ||
ProxyClass = new Function('getCurrentClass', 'return function ' + (InitialClass.name || 'ProxyClass') + '() {\n return getCurrentClass().apply(this, arguments);\n }')(function () { | ||
return CurrentClass; | ||
ProxyComponent = new Function('getCurrentComponent', 'return function ' + (InitialComponent.name || 'ProxyComponent') + '() {\n return getCurrentComponent().apply(this, arguments);\n }')(function () { | ||
return CurrentComponent; | ||
}); | ||
} catch (err) { | ||
// Some environments may forbid dynamic evaluation | ||
ProxyClass = function () { | ||
return CurrentClass.apply(this, arguments); | ||
ProxyComponent = function () { | ||
return CurrentComponent.apply(this, arguments); | ||
}; | ||
} | ||
// Point proxy constructor to the proxy prototype | ||
ProxyClass.prototype = prototypeProxy.get(); | ||
// Proxy toString() to the current constructor | ||
ProxyClass.toString = function toString() { | ||
return CurrentClass.toString(); | ||
ProxyComponent.toString = function toString() { | ||
return CurrentComponent.toString(); | ||
}; | ||
var prototypeProxy = undefined; | ||
if (InitialComponent.prototype && InitialComponent.prototype.isReactComponent) { | ||
// Point proxy constructor to the proxy prototype | ||
prototypeProxy = (0, _createPrototypeProxy2['default'])(); | ||
ProxyComponent.prototype = prototypeProxy.get(); | ||
} | ||
function update(_x) { | ||
@@ -86,7 +89,7 @@ var _again = true; | ||
_function: while (_again) { | ||
var NextClass = _x; | ||
var NextComponent = _x; | ||
mountedInstances = undefined; | ||
_again = false; | ||
if (typeof NextClass !== 'function') { | ||
if (typeof NextComponent !== 'function') { | ||
throw new Error('Expected a constructor.'); | ||
@@ -96,4 +99,4 @@ } | ||
// Prevent proxy cycles | ||
if (Object.prototype.hasOwnProperty.call(NextClass, '__reactPatchProxy')) { | ||
_x = NextClass.__reactPatchProxy.__getCurrent(); | ||
if (Object.prototype.hasOwnProperty.call(NextComponent, '__reactPatchProxy')) { | ||
_x = NextComponent.__reactPatchProxy.__getCurrent(); | ||
_again = true; | ||
@@ -104,15 +107,12 @@ continue _function; | ||
// Save the next constructor so we call it | ||
CurrentClass = NextClass; | ||
CurrentComponent = NextComponent; | ||
// Update the prototype proxy with new methods | ||
var mountedInstances = prototypeProxy.update(NextClass.prototype); | ||
// Try to infer displayName | ||
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name; | ||
// Set up the constructor property so accessing the statics work | ||
ProxyClass.prototype.constructor = ProxyClass; | ||
// Set up the same prototype for inherited statics | ||
ProxyClass.__proto__ = NextClass.__proto__; | ||
ProxyComponent.__proto__ = NextComponent.__proto__; | ||
// Copy static methods and properties | ||
Object.getOwnPropertyNames(NextClass).forEach(function (key) { | ||
Object.getOwnPropertyNames(NextComponent).forEach(function (key) { | ||
if (RESERVED_STATICS.indexOf(key) > -1) { | ||
@@ -122,3 +122,3 @@ return; | ||
var staticDescriptor = _extends({}, Object.getOwnPropertyDescriptor(NextClass, key), { | ||
var staticDescriptor = _extends({}, Object.getOwnPropertyDescriptor(NextComponent, key), { | ||
configurable: true | ||
@@ -129,3 +129,3 @@ }); | ||
if (!wasStaticModifiedByUser(key)) { | ||
Object.defineProperty(ProxyClass, key, staticDescriptor); | ||
Object.defineProperty(ProxyComponent, key, staticDescriptor); | ||
staticDescriptors[key] = staticDescriptor; | ||
@@ -136,3 +136,3 @@ } | ||
// Remove old static methods and properties | ||
Object.getOwnPropertyNames(ProxyClass).forEach(function (key) { | ||
Object.getOwnPropertyNames(ProxyComponent).forEach(function (key) { | ||
if (RESERVED_STATICS.indexOf(key) > -1) { | ||
@@ -143,3 +143,3 @@ return; | ||
// Skip statics that exist on the next class | ||
if (NextClass.hasOwnProperty(key)) { | ||
if (NextComponent.hasOwnProperty(key)) { | ||
return; | ||
@@ -149,3 +149,3 @@ } | ||
// Skip non-configurable statics | ||
var descriptor = Object.getOwnPropertyDescriptor(ProxyClass, key); | ||
var descriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key); | ||
if (descriptor && !descriptor.configurable) { | ||
@@ -157,3 +157,3 @@ return; | ||
if (!wasStaticModifiedByUser(key)) { | ||
delete ProxyClass[key]; | ||
delete ProxyComponent[key]; | ||
delete staticDescriptors[key]; | ||
@@ -163,11 +163,13 @@ } | ||
// Try to infer displayName | ||
ProxyClass.displayName = NextClass.displayName || NextClass.name; | ||
if (prototypeProxy) { | ||
// Update the prototype proxy with new methods | ||
var mountedInstances = prototypeProxy.update(NextComponent.prototype); | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(_bindAutoBindMethods2['default']); | ||
mountedInstances.forEach(_deleteUnknownAutoBindMethods2['default']); | ||
// Set up the constructor property so accessing the statics work | ||
ProxyComponent.prototype.constructor = ProxyComponent; | ||
// Let the user take care of redrawing | ||
return mountedInstances; | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(_bindAutoBindMethods2['default']); | ||
mountedInstances.forEach(_deleteUnknownAutoBindMethods2['default']); | ||
} | ||
} | ||
@@ -177,10 +179,10 @@ }; | ||
function get() { | ||
return ProxyClass; | ||
return ProxyComponent; | ||
} | ||
function getCurrent() { | ||
return CurrentClass; | ||
return CurrentComponent; | ||
} | ||
update(InitialClass); | ||
update(InitialComponent); | ||
@@ -196,3 +198,3 @@ var proxy = { get: get, update: update }; | ||
Object.defineProperty(ProxyClass, '__reactPatchProxy', { | ||
Object.defineProperty(ProxyComponent, '__reactPatchProxy', { | ||
configurable: false, | ||
@@ -199,0 +201,0 @@ writable: false, |
@@ -7,10 +7,9 @@ 'use strict'; | ||
function _interopRequire(obj) { return obj && obj.__esModule ? obj['default'] : obj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _createClassProxy = require('./createClassProxy'); | ||
exports.createProxy = _interopRequire(_createClassProxy); | ||
var _createClassProxy2 = _interopRequireDefault(_createClassProxy); | ||
var _reactDeepForceUpdate = require('react-deep-force-update'); | ||
exports.getForceUpdate = _interopRequire(_reactDeepForceUpdate); | ||
exports['default'] = _createClassProxy2['default']; | ||
module.exports = exports['default']; |
{ | ||
"name": "react-proxy", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "Proxies React components without unmounting or losing their state.", | ||
@@ -28,3 +28,4 @@ "main": "modules/index.js", | ||
"mocha": "^2.2.4", | ||
"react": "^0.13.2", | ||
"react": "^0.14.0", | ||
"react-addons-test-utils": "^0.14.0", | ||
"rimraf": "^2.4.2", | ||
@@ -34,5 +35,4 @@ "webpack": "1.4.8" | ||
"dependencies": { | ||
"lodash": "^3.7.0", | ||
"react-deep-force-update": "^1.0.0" | ||
"lodash": "^3.7.0" | ||
} | ||
} |
# React Proxy [](https://travis-ci.org/gaearon/react-proxy) [](https://www.npmjs.com/package/react-proxy) | ||
A generic React component proxy used as the new engine by React Hot Loader. | ||
A generic React component proxy useful for hot reloading. | ||
## Requirements | ||
* React 0.13+ | ||
* React 0.14+ | ||
@@ -14,2 +14,4 @@ ## Usage | ||
You will need something like [react-deep-force-update](https://github.com/gaearon/react-deep-force-update) to re-render the component tree after applying the update. | ||
```js | ||
@@ -44,3 +46,6 @@ import React, { Component } from 'react'; | ||
```js | ||
import { createProxy, getForceUpdate } from 'react-proxy'; | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import createProxy from 'react-proxy'; | ||
import deepForceUpdate from 'react-deep-force-update'; | ||
@@ -55,22 +60,22 @@ // Create a proxy object, given the initial React component class. | ||
// Render the component (proxy, really). | ||
React.render(<Proxy />, rootEl); | ||
const rootInstance = render(<Proxy />, rootEl); | ||
// Point the proxy to the new React component class by calling update(). | ||
// Instances will stay mounted and their state will be intact, but their methods will be updated. | ||
// The update() method returns an array of mounted instances so we can do something with them. | ||
const mountedInstances = proxy.update(ComponentVersion2); | ||
proxy.update(ComponentVersion2); | ||
// React Proxy also provides us with getForceUpdate() method that works even if the component | ||
// instance doesn't descend from React.Component, and doesn't have a forceUpdate() method. | ||
const forceUpdate = getForceUpdate(React); | ||
// Force-update all the affected instances! | ||
mountedInstances.forEach(forceUpdate); | ||
// Force-update the whole React component tree. | ||
// Until React provides an official DevTools API to do this, | ||
// you should keep the reference to the root instance(s). | ||
deepForceUpdate(rootInstance); | ||
``` | ||
## React Native | ||
This will work with React Native when [facebook/react-native#2985](https://github.com/facebook/react-native/issues/2985) lands. | ||
For now, you can keep using 1.x. | ||
## Features | ||
* Supports both classic (`React.createClass()`) and modern (ES6 classes) style | ||
* Supports classes that don’t descend from `React.Component` | ||
* Supports classes with strict `shouldComponentUpdate` | ||
* Supports inherited and base classes (although you shouldn’t use inheritance with React) | ||
@@ -77,0 +82,0 @@ * Supports classic `createClass()` autobinding and modern [`autobind-decorator`](https://github.com/andreypopp/autobind-decorator) |
@@ -29,11 +29,11 @@ import createPrototypeProxy from './createPrototypeProxy'; | ||
export default function proxyClass(InitialClass) { | ||
export default function proxyClass(InitialComponent) { | ||
// Prevent double wrapping. | ||
// Given a proxy class, return the existing proxy managing it. | ||
if (Object.prototype.hasOwnProperty.call(InitialClass, '__reactPatchProxy')) { | ||
return InitialClass.__reactPatchProxy; | ||
if (Object.prototype.hasOwnProperty.call(InitialComponent, '__reactPatchProxy')) { | ||
return InitialComponent.__reactPatchProxy; | ||
} | ||
const prototypeProxy = createPrototypeProxy(); | ||
let CurrentClass; | ||
let CurrentComponent; | ||
let ProxyComponent; | ||
@@ -43,31 +43,34 @@ let staticDescriptors = {}; | ||
// Compare the descriptor with the one we previously set ourselves. | ||
const currentDescriptor = Object.getOwnPropertyDescriptor(ProxyClass, key); | ||
const currentDescriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key); | ||
return !isEqualDescriptor(staticDescriptors[key], currentDescriptor); | ||
} | ||
let ProxyClass; | ||
try { | ||
// Create a proxy constructor with matching name | ||
ProxyClass = new Function('getCurrentClass', | ||
`return function ${InitialClass.name || 'ProxyClass'}() { | ||
return getCurrentClass().apply(this, arguments); | ||
ProxyComponent = new Function('getCurrentComponent', | ||
`return function ${InitialComponent.name || 'ProxyComponent'}() { | ||
return getCurrentComponent().apply(this, arguments); | ||
}` | ||
)(() => CurrentClass); | ||
)(() => CurrentComponent); | ||
} catch (err) { | ||
// Some environments may forbid dynamic evaluation | ||
ProxyClass = function () { | ||
return CurrentClass.apply(this, arguments); | ||
ProxyComponent = function () { | ||
return CurrentComponent.apply(this, arguments); | ||
}; | ||
} | ||
// Point proxy constructor to the proxy prototype | ||
ProxyClass.prototype = prototypeProxy.get(); | ||
// Proxy toString() to the current constructor | ||
ProxyClass.toString = function toString() { | ||
return CurrentClass.toString(); | ||
ProxyComponent.toString = function toString() { | ||
return CurrentComponent.toString(); | ||
}; | ||
function update(NextClass) { | ||
if (typeof NextClass !== 'function') { | ||
let prototypeProxy; | ||
if (InitialComponent.prototype && InitialComponent.prototype.isReactComponent) { | ||
// Point proxy constructor to the proxy prototype | ||
prototypeProxy = createPrototypeProxy(); | ||
ProxyComponent.prototype = prototypeProxy.get(); | ||
} | ||
function update(NextComponent) { | ||
if (typeof NextComponent !== 'function') { | ||
throw new Error('Expected a constructor.'); | ||
@@ -77,20 +80,17 @@ } | ||
// Prevent proxy cycles | ||
if (Object.prototype.hasOwnProperty.call(NextClass, '__reactPatchProxy')) { | ||
return update(NextClass.__reactPatchProxy.__getCurrent()); | ||
if (Object.prototype.hasOwnProperty.call(NextComponent, '__reactPatchProxy')) { | ||
return update(NextComponent.__reactPatchProxy.__getCurrent()); | ||
} | ||
// Save the next constructor so we call it | ||
CurrentClass = NextClass; | ||
CurrentComponent = NextComponent; | ||
// Update the prototype proxy with new methods | ||
const mountedInstances = prototypeProxy.update(NextClass.prototype); | ||
// Try to infer displayName | ||
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name; | ||
// Set up the constructor property so accessing the statics work | ||
ProxyClass.prototype.constructor = ProxyClass; | ||
// Set up the same prototype for inherited statics | ||
ProxyClass.__proto__ = NextClass.__proto__; | ||
ProxyComponent.__proto__ = NextComponent.__proto__; | ||
// Copy static methods and properties | ||
Object.getOwnPropertyNames(NextClass).forEach(key => { | ||
Object.getOwnPropertyNames(NextComponent).forEach(key => { | ||
if (RESERVED_STATICS.indexOf(key) > -1) { | ||
@@ -101,3 +101,3 @@ return; | ||
const staticDescriptor = { | ||
...Object.getOwnPropertyDescriptor(NextClass, key), | ||
...Object.getOwnPropertyDescriptor(NextComponent, key), | ||
configurable: true | ||
@@ -108,3 +108,3 @@ }; | ||
if (!wasStaticModifiedByUser(key)) { | ||
Object.defineProperty(ProxyClass, key, staticDescriptor); | ||
Object.defineProperty(ProxyComponent, key, staticDescriptor); | ||
staticDescriptors[key] = staticDescriptor; | ||
@@ -115,3 +115,3 @@ } | ||
// Remove old static methods and properties | ||
Object.getOwnPropertyNames(ProxyClass).forEach(key => { | ||
Object.getOwnPropertyNames(ProxyComponent).forEach(key => { | ||
if (RESERVED_STATICS.indexOf(key) > -1) { | ||
@@ -122,3 +122,3 @@ return; | ||
// Skip statics that exist on the next class | ||
if (NextClass.hasOwnProperty(key)) { | ||
if (NextComponent.hasOwnProperty(key)) { | ||
return; | ||
@@ -128,3 +128,3 @@ } | ||
// Skip non-configurable statics | ||
const descriptor = Object.getOwnPropertyDescriptor(ProxyClass, key); | ||
const descriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key); | ||
if (descriptor && !descriptor.configurable) { | ||
@@ -136,3 +136,3 @@ return; | ||
if (!wasStaticModifiedByUser(key)) { | ||
delete ProxyClass[key]; | ||
delete ProxyComponent[key]; | ||
delete staticDescriptors[key]; | ||
@@ -142,22 +142,24 @@ } | ||
// Try to infer displayName | ||
ProxyClass.displayName = NextClass.displayName || NextClass.name; | ||
if (prototypeProxy) { | ||
// Update the prototype proxy with new methods | ||
const mountedInstances = prototypeProxy.update(NextComponent.prototype); | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(bindAutoBindMethods); | ||
mountedInstances.forEach(deleteUnknownAutoBindMethods); | ||
// Set up the constructor property so accessing the statics work | ||
ProxyComponent.prototype.constructor = ProxyComponent; | ||
// Let the user take care of redrawing | ||
return mountedInstances; | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(bindAutoBindMethods); | ||
mountedInstances.forEach(deleteUnknownAutoBindMethods); | ||
} | ||
}; | ||
function get() { | ||
return ProxyClass; | ||
return ProxyComponent; | ||
} | ||
function getCurrent() { | ||
return CurrentClass; | ||
return CurrentComponent; | ||
} | ||
update(InitialClass); | ||
update(InitialComponent); | ||
@@ -173,3 +175,3 @@ const proxy = { get, update }; | ||
Object.defineProperty(ProxyClass, '__reactPatchProxy', { | ||
Object.defineProperty(ProxyComponent, '__reactPatchProxy', { | ||
configurable: false, | ||
@@ -176,0 +178,0 @@ writable: false, |
@@ -1,2 +0,1 @@ | ||
export { default as createProxy } from './createClassProxy'; | ||
export { default as getForceUpdate } from 'react-deep-force-update'; | ||
export default from './createClassProxy'; |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
1
-50%110
4.76%88561
-0.72%9
12.5%2394
-1.2%- Removed
- Removed