react-hot-loader
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -8,3 +8,3 @@ /** @jsx React.DOM */ | ||
return ( | ||
<div style={{background: 'purple',color: 'white'}}> | ||
<div style={{background: 'purple', color: 'white'}}> | ||
<p>I am <code>example/b.jsx</code>, feel free to edit me.</p> | ||
@@ -11,0 +11,0 @@ <img src='http://facebook.github.io/react/img/logo_og.png' width='200' /> |
90
hot.js
'use strict'; | ||
var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) { | ||
/* jshint proto:true */ | ||
obj.__proto__ = proto; | ||
return obj; | ||
}; | ||
module.exports = function (React) { | ||
@@ -22,53 +16,66 @@ var mounted = []; | ||
var assimilatePrototype = (function () { | ||
var storedPrototype; | ||
var storedPrototype, | ||
knownPrototypes = []; | ||
function assimilateProperty(freshPrototype, key) { | ||
function get() { | ||
if (typeof storedPrototype[key] !== 'function' || | ||
key === 'type' || | ||
key === 'constructor') { | ||
return storedPrototype[key]; | ||
function wrapFunction(key) { | ||
return function () { | ||
if (storedPrototype[key]) { | ||
return storedPrototype[key].apply(this, arguments); | ||
} | ||
}; | ||
} | ||
return function () { | ||
var value = storedPrototype[key]; | ||
if (typeof value === 'function') { | ||
return value.apply(this, arguments); | ||
} else { | ||
console.warn('A call to ' + key + ' was made after it was deleted. Acting as no-op.'); | ||
} | ||
}; | ||
function patchProperty(proto, key) { | ||
proto[key] = storedPrototype[key]; | ||
if (typeof proto[key] !== 'function' || | ||
key === 'type' || | ||
key === 'constructor') { | ||
return; | ||
} | ||
function set(value) { | ||
storedPrototype[key] = value; | ||
proto[key] = wrapFunction(key); | ||
if (proto.__reactAutoBindMap[key]) { | ||
proto.__reactAutoBindMap[key] = proto[key]; | ||
} | ||
storedPrototype[key] = freshPrototype[key]; | ||
Object.defineProperty(freshPrototype, key, { | ||
configurable: false, | ||
enumerable: true, | ||
get: get, | ||
set: set | ||
}); | ||
} | ||
return function assimilatePrototype(freshPrototype) { | ||
function updateStoredPrototype(freshPrototype) { | ||
storedPrototype = {}; | ||
for (var key in freshPrototype) { | ||
assimilateProperty(freshPrototype, key); | ||
if (freshPrototype.hasOwnProperty(key)) { | ||
storedPrototype[key] = freshPrototype[key]; | ||
} | ||
} | ||
} | ||
function reconcileWithStoredPrototypes(freshPrototype) { | ||
knownPrototypes.push(freshPrototype); | ||
knownPrototypes.forEach(function (proto) { | ||
for (var key in storedPrototype) { | ||
patchProperty(proto, key); | ||
} | ||
}); | ||
} | ||
return function (freshPrototype) { | ||
updateStoredPrototype(freshPrototype); | ||
reconcileWithStoredPrototypes(freshPrototype); | ||
}; | ||
})(); | ||
function injectMixinAndAssimilatePrototype(spec) { | ||
spec.mixins = spec.mixins || []; | ||
spec.mixins.push(Mixin); | ||
var Component = React.createClass(spec); | ||
assimilatePrototype(Component.type.prototype); | ||
return Component; | ||
} | ||
var Component; | ||
return { | ||
createClass: function (spec) { | ||
spec.mixins = spec.mixins || []; | ||
spec.mixins.push(Mixin); | ||
Component = React.createClass(spec); | ||
assimilatePrototype(Component.componentConstructor.prototype); | ||
Component = injectMixinAndAssimilatePrototype(spec); | ||
return Component; | ||
@@ -78,4 +85,3 @@ }, | ||
updateClass: function (spec) { | ||
var UpdatedComponent = React.createClass(spec); | ||
assimilatePrototype(UpdatedComponent.componentConstructor.prototype); | ||
injectMixinAndAssimilatePrototype(spec); | ||
@@ -82,0 +88,0 @@ mounted.forEach(function (instance) { |
{ | ||
"name": "react-hot-loader", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Webpack loader that enables live-editing React components without unmounting or losing their state", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7929
184