UNPKG

10.1 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory();
4 else if(typeof define === 'function' && define.amd)
5 define(factory);
6 else if(typeof exports === 'object')
7 exports["ReactHotAPI"] = factory();
8 else
9 root["ReactHotAPI"] = factory();
10})(this, function() {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14/******/
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17/******/
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId])
20/******/ return installedModules[moduleId].exports;
21/******/
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ exports: {},
25/******/ id: moduleId,
26/******/ loaded: false
27/******/ };
28/******/
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31/******/
32/******/ // Flag the module as loaded
33/******/ module.loaded = true;
34/******/
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38/******/
39/******/
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42/******/
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45/******/
46/******/ // __webpack_public_path__
47/******/ __webpack_require__.p = "";
48/******/
49/******/ // Load entry module and return exports
50/******/ return __webpack_require__(0);
51/******/ })
52/************************************************************************/
53/******/ ([
54/* 0 */
55/***/ function(module, exports, __webpack_require__) {
56
57 'use strict';
58
59 module.exports = __webpack_require__(4);
60
61/***/ },
62/* 1 */
63/***/ function(module, exports, __webpack_require__) {
64
65 'use strict';
66
67 /**
68 * Based on https://github.com/facebook/react/blob/master/src/class/ReactClass.js#L637
69 */
70 function bindAutoBindMethod(component, method) {
71 var boundMethod = method.bind(component);
72
73 boundMethod.__reactBoundContext = component;
74 boundMethod.__reactBoundMethod = method;
75 boundMethod.__reactBoundArguments = null;
76
77 var componentName = component.constructor.displayName,
78 _bind = boundMethod.bind;
79
80 boundMethod.bind = function (newThis) {
81 var args = Array.prototype.slice.call(arguments, 1);
82 if (newThis !== component && newThis !== null) {
83 console.warn(
84 'bind(): React component methods may only be bound to the ' +
85 'component instance. See ' + componentName
86 );
87 } else if (!args.length) {
88 console.warn(
89 'bind(): You are binding a component method to the component. ' +
90 'React does this for you automatically in a high-performance ' +
91 'way, so you can safely remove this call. See ' + componentName
92 );
93 return boundMethod;
94 }
95
96 var reboundMethod = _bind.apply(boundMethod, arguments);
97 reboundMethod.__reactBoundContext = component;
98 reboundMethod.__reactBoundMethod = method;
99 reboundMethod.__reactBoundArguments = args;
100
101 return reboundMethod;
102 };
103
104 return boundMethod;
105 }
106
107 /**
108 * Performs auto-binding similar to how React does it.
109 * Skips already auto-bound methods.
110 * Based on https://github.com/facebook/react/blob/master/src/class/ReactClass.js#L679.
111 */
112 module.exports = function bindAutoBindMethods(component) {
113 for (var autoBindKey in component.__reactAutoBindMap) {
114 if (!component.__reactAutoBindMap.hasOwnProperty(autoBindKey)) {
115 continue;
116 }
117
118 // Skip already bound methods
119 if (component.hasOwnProperty(autoBindKey) &&
120 component[autoBindKey].__reactBoundContext === component) {
121 continue;
122 }
123
124 var method = component.__reactAutoBindMap[autoBindKey];
125 component[autoBindKey] = bindAutoBindMethod(component, method);
126 }
127 };
128
129/***/ },
130/* 2 */
131/***/ function(module, exports, __webpack_require__) {
132
133 'use strict';
134
135 var bindAutoBindMethods = __webpack_require__(1);
136
137 /**
138 * Updates a React component recursively, so even if children define funky
139 * `shouldComponentUpdate`, they are forced to re-render.
140 * Makes sure that any newly added methods are properly auto-bound.
141 */
142 function deepForceUpdate(component) {
143 if (component._instance) {
144 // React 0.13
145 component = component._instance;
146 }
147
148 bindAutoBindMethods(component);
149
150 if (component.forceUpdate) {
151 component.forceUpdate();
152 }
153
154 if (component._renderedComponent) {
155 deepForceUpdate(component._renderedComponent);
156 }
157
158 for (var key in component._renderedChildren) {
159 deepForceUpdate(component._renderedChildren[key]);
160 }
161 }
162
163 module.exports = deepForceUpdate;
164
165/***/ },
166/* 3 */
167/***/ function(module, exports, __webpack_require__) {
168
169 'use strict';
170
171 /**
172 * Returns a function that establishes the first prototype passed to it
173 * as the "source of truth" and patches its methods on subsequent invocations,
174 * also patching current and previous prototypes to forward calls to it.
175 */
176 module.exports = function makeAssimilatePrototype() {
177 var storedPrototype,
178 knownPrototypes = [];
179
180 function wrapMethod(key) {
181 return function () {
182 if (storedPrototype[key]) {
183 return storedPrototype[key].apply(this, arguments);
184 }
185 };
186 }
187
188 function patchProperty(proto, key) {
189 proto[key] = storedPrototype[key];
190
191 if (typeof proto[key] !== 'function' ||
192 key === 'type' ||
193 key === 'constructor') {
194 return;
195 }
196
197 proto[key] = wrapMethod(key);
198
199 if (storedPrototype[key].isReactClassApproved) {
200 proto[key].isReactClassApproved = storedPrototype[key].isReactClassApproved;
201 }
202
203 if (proto.__reactAutoBindMap && proto.__reactAutoBindMap[key]) {
204 proto.__reactAutoBindMap[key] = proto[key];
205 }
206 }
207
208 function updateStoredPrototype(freshPrototype) {
209 storedPrototype = {};
210
211 for (var key in freshPrototype) {
212 if (freshPrototype.hasOwnProperty(key)) {
213 storedPrototype[key] = freshPrototype[key];
214 }
215 }
216 }
217
218 function reconcileWithStoredPrototypes(freshPrototype) {
219 knownPrototypes.push(freshPrototype);
220 knownPrototypes.forEach(function (proto) {
221 for (var key in storedPrototype) {
222 patchProperty(proto, key);
223 }
224 });
225 }
226
227 return function assimilatePrototype(freshPrototype) {
228 if (freshPrototype.__isAssimilatedByReactHotAPI) {
229 return;
230 }
231
232 updateStoredPrototype(freshPrototype);
233 reconcileWithStoredPrototypes(freshPrototype);
234 freshPrototype.__isAssimilatedByReactHotAPI = true;
235 };
236 };
237
238/***/ },
239/* 4 */
240/***/ function(module, exports, __webpack_require__) {
241
242 'use strict';
243
244 var makePatchReactClass = __webpack_require__(5);
245
246 /**
247 * Returns a function that, when invoked, patches a React class with a new
248 * version of itself. To patch different classes, pass different IDs.
249 */
250 module.exports = function makeMakeHot(getRootInstances) {
251 if (typeof getRootInstances !== 'function') {
252 throw new Error('Expected getRootInstances to be a function.');
253 }
254
255 var patchers = {};
256
257 return function makeHot(NextClass, persistentId) {
258 persistentId = persistentId || NextClass.displayName || NextClass.name;
259
260 if (!persistentId) {
261 console.error(
262 'Hot reload is disabled for one of your types. To enable it, pass a ' +
263 'string uniquely identifying this class within this current module ' +
264 'as a second parameter to makeHot.'
265 );
266 return NextClass;
267 }
268
269 if (!patchers[persistentId]) {
270 patchers[persistentId] = makePatchReactClass(getRootInstances);
271 }
272
273 var patchReactClass = patchers[persistentId];
274 return patchReactClass(NextClass);
275 };
276 };
277
278/***/ },
279/* 5 */
280/***/ function(module, exports, __webpack_require__) {
281
282 'use strict';
283
284 var makeAssimilatePrototype = __webpack_require__(3),
285 requestForceUpdateAll = __webpack_require__(6);
286
287 function hasLegacyTypeProperty(ReactClass) {
288 if (!ReactClass.hasOwnProperty('type')) {
289 return false;
290 }
291
292 var descriptor = Object.getOwnPropertyDescriptor(ReactClass, 'type');
293 if (typeof descriptor.get === 'function') {
294 return false;
295 }
296
297 return true;
298 }
299
300 function getPrototype(ReactClass) {
301 var prototype = ReactClass.prototype;
302
303 if (typeof prototype.render !== 'function' && hasLegacyTypeProperty(ReactClass)) {
304 prototype = ReactClass.type.prototype;
305 }
306
307 return prototype;
308 }
309
310 /**
311 * Returns a function that will patch React class with new versions of itself
312 * on subsequent invocations. Both legacy and ES6 style classes are supported.
313 */
314 module.exports = function makePatchReactClass(getRootInstances) {
315 var assimilatePrototype = makeAssimilatePrototype(),
316 FirstClass = null;
317
318 return function patchReactClass(NextClass) {
319 var nextPrototype = getPrototype(NextClass);
320 assimilatePrototype(nextPrototype);
321
322 if (FirstClass) {
323 requestForceUpdateAll(getRootInstances);
324 }
325
326 return FirstClass || (FirstClass = NextClass);
327 };
328 };
329
330/***/ },
331/* 6 */
332/***/ function(module, exports, __webpack_require__) {
333
334 var deepForceUpdate = __webpack_require__(2);
335
336 var isRequestPending = false;
337
338 module.exports = function requestForceUpdateAll(getRootInstances) {
339 if (isRequestPending) {
340 return;
341 }
342
343 /**
344 * Forces deep re-render of all mounted React components.
345 * Hat's off to Omar Skalli (@Chetane) for suggesting this approach:
346 * https://gist.github.com/Chetane/9a230a9fdcdca21a4e29
347 */
348 function forceUpdateAll() {
349 isRequestPending = false;
350
351 var rootInstances = getRootInstances(),
352 rootInstance;
353
354 for (var key in rootInstances) {
355 if (rootInstances.hasOwnProperty(key)) {
356 deepForceUpdate(rootInstances[key]);
357 }
358 }
359 }
360
361 setTimeout(forceUpdateAll);
362 };
363
364/***/ }
365/******/ ])
366});