UNPKG

1.06 kBJavaScriptView Raw
1'use strict';
2
3var makePatchReactClass = require('./makePatchReactClass');
4
5/**
6 * Returns a function that, when invoked, patches a React class with a new
7 * version of itself. To patch different classes, pass different IDs.
8 */
9module.exports = function makeMakeHot(getRootInstances) {
10 if (typeof getRootInstances !== 'function') {
11 throw new Error('Expected getRootInstances to be a function.');
12 }
13
14 var patchers = {};
15
16 return function makeHot(NextClass, persistentId) {
17 persistentId = persistentId || NextClass.displayName || NextClass.name;
18
19 if (!persistentId) {
20 console.error(
21 'Hot reload is disabled for one of your types. To enable it, pass a ' +
22 'string uniquely identifying this class within this current module ' +
23 'as a second parameter to makeHot.'
24 );
25 return NextClass;
26 }
27
28 if (!patchers[persistentId]) {
29 patchers[persistentId] = makePatchReactClass(getRootInstances);
30 }
31
32 var patchReactClass = patchers[persistentId];
33 return patchReactClass(NextClass);
34 };
35};
\No newline at end of file