mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Move hot api to hot-module-replacement package
This commit is contained in:
45
packages/hot-module-replacement/hot-api.js
Normal file
45
packages/hot-module-replacement/hot-api.js
Normal 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() { }
|
||||
});
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user