react-hot-api
Advanced tools
Comparing version 0.5.0-alpha-3 to 0.5.0
@@ -596,3 +596,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
// Given a proxy class, return the existing proxy managing it. | ||
if (InitialClass.__reactPatchProxy) { | ||
if (Object.prototype.hasOwnProperty.call(InitialClass, '__reactPatchProxy')) { | ||
return InitialClass.__reactPatchProxy; | ||
@@ -612,28 +612,43 @@ } | ||
function update(NextClass) { | ||
if (typeof NextClass !== 'function') { | ||
throw new Error('Expected a constructor.'); | ||
} | ||
function update(_x) { | ||
var _again = true; | ||
// Save the next constructor so we call it | ||
CurrentClass = NextClass; | ||
_function: while (_again) { | ||
var NextClass = _x; | ||
mountedInstances = undefined; | ||
_again = false; | ||
// Update the prototype proxy with new methods | ||
var mountedInstances = prototypeProxy.update(NextClass.prototype); | ||
if (typeof NextClass !== 'function') { | ||
throw new Error('Expected a constructor.'); | ||
} | ||
// Set up the constructor property so accessing the statics work | ||
ProxyClass.prototype.constructor = ProxyClass; | ||
// Prevent proxy cycles | ||
if (Object.prototype.hasOwnProperty.call(NextClass, '__reactPatchProxy')) { | ||
_x = NextClass.__reactPatchProxy.__getCurrent(); | ||
_again = true; | ||
continue _function; | ||
} | ||
// Naïvely proxy static methods and properties | ||
ProxyClass.prototype.constructor.__proto__ = NextClass; | ||
// Save the next constructor so we call it | ||
CurrentClass = NextClass; | ||
// Try to infer displayName | ||
ProxyClass.displayName = NextClass.name || NextClass.displayName; | ||
// Update the prototype proxy with new methods | ||
var mountedInstances = prototypeProxy.update(NextClass.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 | ||
ProxyClass.prototype.constructor = ProxyClass; | ||
// Let the user take care of redrawing | ||
return mountedInstances; | ||
// Naïvely proxy static methods and properties | ||
ProxyClass.prototype.constructor.__proto__ = NextClass; | ||
// Try to infer displayName | ||
ProxyClass.displayName = NextClass.name || NextClass.displayName; | ||
// We might have added new methods that need to be auto-bound | ||
mountedInstances.forEach(_bindAutoBindMethods2['default']); | ||
mountedInstances.forEach(_deleteUnknownAutoBindMethods2['default']); | ||
// Let the user take care of redrawing | ||
return mountedInstances; | ||
} | ||
}; | ||
@@ -645,10 +660,24 @@ | ||
function getCurrent() { | ||
return CurrentClass; | ||
} | ||
update(InitialClass); | ||
var proxy = { | ||
get: get, | ||
update: update | ||
}; | ||
var proxy = { get: get, update: update }; | ||
ProxyClass.__reactPatchProxy = proxy; | ||
Object.defineProperty(proxy, '__getCurrent', { | ||
configurable: false, | ||
writable: false, | ||
enumerable: false, | ||
value: getCurrent | ||
}); | ||
Object.defineProperty(ProxyClass, '__reactPatchProxy', { | ||
configurable: false, | ||
writable: false, | ||
enumerable: false, | ||
value: proxy | ||
}); | ||
return proxy; | ||
@@ -686,2 +715,16 @@ } | ||
/** | ||
* Creates a proxied toString() method pointing to the current version's toString(). | ||
*/ | ||
function proxyToString(name) { | ||
// Wrap to always call the current version | ||
return function toString() { | ||
if (typeof current[name] === 'function') { | ||
return current[name].toString(); | ||
} else { | ||
return '<method was deleted>'; | ||
} | ||
}; | ||
} | ||
/** | ||
* Creates a proxied method that calls the current version, whenever available. | ||
@@ -699,2 +742,4 @@ */ | ||
(0, _lodashObjectAssign2['default'])(proxiedMethod, current[name]); | ||
proxiedMethod.toString = proxyToString(name); | ||
return proxiedMethod; | ||
@@ -712,2 +757,3 @@ } | ||
} | ||
proxiedComponentDidMount.toString = proxyToString('componentDidMount'); | ||
@@ -727,2 +773,3 @@ /** | ||
} | ||
proxiedComponentWillUnmount.toString = proxyToString('componentWillUnmount'); | ||
@@ -729,0 +776,0 @@ /** |
{ | ||
"name": "react-hot-api", | ||
"version": "0.5.0-alpha-3", | ||
"version": "0.5.0", | ||
"description": "A generic library implementing hot reload for React components without unmounting or losing their state.", | ||
@@ -26,4 +26,4 @@ "main": "modules/index.js", | ||
"dependencies": { | ||
"react-proxy": "^0.6.6" | ||
"react-proxy": "^1.0.0" | ||
} | ||
} |
@@ -0,1 +1,5 @@ | ||
># Deprecation Notice | ||
>Don’t use this for new projects. | ||
>[React Proxy](https://github.com/gaearon/react-proxy) is much more advanced, has a better API, and is covered by tests. | ||
React Hot API | ||
@@ -2,0 +6,0 @@ ========= |
61639
1607
146
+ Addedlodash@4.17.21(transitive)
+ Addedreact-deep-force-update@1.1.2(transitive)
+ Addedreact-proxy@1.1.8(transitive)
- Removedlodash@3.10.1(transitive)
- Removedreact-proxy@0.6.7(transitive)
Updatedreact-proxy@^1.0.0