Fixes circular dependency issue between runtime/index.js and hot-reload/index.js

This commit is contained in:
Phillip Gates-Idem 2016-02-09 18:51:55 -05:00
parent f0fe0e4c0a
commit a3f4a823a4

View File

@ -19,19 +19,29 @@ require('raptor-polyfill/string/endsWith');
var extend = require('raptor-util/extend');
var compiler = require('../compiler');
var nodePath = require('path');
var runtime = require('../runtime');
var Template = runtime.Template;
var modifiedFlag = 1;
var runtime;
/**
* Lazily require the Marko runtime because there is a circular dependency.
* We need to export our `enable` function before actually requiring the
* Marko runtime.
*/
function _getMarkoRuntime() {
return runtime || (runtime = require('../runtime'));
}
exports.enable = function() {
var runtime = _getMarkoRuntime();
if (runtime.__hotReloadEnabled) {
// Marko has already been monkey-patched. Nothing to do!
return;
}
var Template = runtime.Template;
runtime.__hotReloadEnabled = true;
// We set an environment variable so that _all_ marko modules
@ -93,7 +103,7 @@ exports.enable = function() {
};
exports.handleFileModified = function(path) {
var runtime = _getMarkoRuntime();
var basename = nodePath.basename(path);
if (path.endsWith('.marko') ||