Move hot api to hot-module-replacement package

This commit is contained in:
zodern
2021-01-14 16:54:45 -06:00
parent 59bf534baa
commit cc70a2ad0a
3 changed files with 49 additions and 46 deletions

View File

@@ -0,0 +1,45 @@
const meteorInstall = Package['modules-runtime'].meteorInstall;
Object.defineProperty(meteorInstall.Module.prototype, "hot", {
get: function () {
if (!this._hotState) {
this._hotState = {
// if null, whether it accepts depends on all of the modules that
// required it
_hotAccepts: null,
_disposeHandlers: [],
data: null
};
}
let hotState = this._hotState;
let module = this;
return {
accept() {
if (arguments.length > 0) {
console.warn('hot.accept does not support any arguments.');
}
hotState._hotAccepts = true;
},
decline() {
if (arguments.length > 0) {
throw new Error('hot.decline does not support any arguments.');
}
hotState._hotAccepts = false;
},
dispose(cb) {
hotState._disposeHandlers.push(cb);
},
onRequire(callbacks) {
return module._onRequire(callbacks);
},
_canAcceptUpdate() {
return hotState._hotAccepts;
},
data: hotState.data
}
},
set() { }
});

View File

@@ -10,7 +10,10 @@ Package.onUse(function (api) {
api.use('modules');
api.use('meteor');
api.imply('modules-runtime-hot@0.12.0');
api.addFiles('./client.js', 'client');
api.addFiles([
'./hot-api.js',
'./client.js'
], 'client');
api.addFiles('./server.js', 'server');
});

View File

@@ -20,51 +20,6 @@ meteorInstall = makeInstaller({
let Module = Package['modules-runtime'].meteorInstall.Module;
meteorInstall.Module.prototype.link = Module.prototype.link;
Object.defineProperty(meteorInstall.Module.prototype, "hot", {
get: function () {
if (!this._hotState) {
this._hotState = {
// if null, whether it accepts depends on all of the modules that
// required it
_hotAccepts: null,
_disposeHandlers: [],
data: null
};
}
let hotState = this._hotState;
let module = this;
return {
accept() {
if (arguments.length > 0) {
// TODO: support same options as webpack
console.warn('hot.accept does not support any arguments.');
}
hotState._hotAccepts = true;
},
decline() {
if (arguments.length > 0) {
throw new Error('hot.decline does not support any arguments.');
}
hotState._hotAccepts = false;
},
dispose(cb) {
hotState._disposeHandlers.push(cb);
},
onRequire(callbacks) {
return module._onRequire(callbacks);
},
_canAcceptUpdate() {
return hotState._hotAccepts;
},
data: hotState.data
}
},
set() {}
});
// This package should be running after modules-runtime but before modules.
// We want modules to use our patched meteorInstall
Package['modules-runtime'].meteorInstall = meteorInstall;