Skip to content

Commit

Permalink
mod: lazyAppReload is false by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hefangshi committed Jun 29, 2016
1 parent c22dd7c commit 024f873
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 7 additions & 5 deletions plugins/isomorphic/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
var Module = require('module');
var frontendCache = {};
var frontendFactoryCache = {};
var frontendLoaded = {};
var debuglog = require('debuglog')('yog/isomorphic');

module.exports.isomorphic = ['views', function (app, conf) {
var namespaceConnector = conf.namespaceConnector || ':';

global.define = function (id, factory) {
debuglog('isomorphic script', id, 'loaded');
frontendFactoryCache['frontend_' + id] = factory;
};

function getDeps(id) {
function getDeps(id, loaded) {
let deps = [];
var info = app.fis.getInfo(id);
if (!info) {
return deps;
}
if (info.deps) {
info.deps.forEach(dep => {
deps = deps.concat(getDeps(dep));
deps = deps.concat(getDeps(dep, loaded));
});
}
if (info.type === 'js') {
if (info.type === 'js' && !loaded[info.subpath]) {
if (!info.subpath) {
throw new Error('Please update your yog2 cli version to support isomorphic mode.');
}
loaded[info.subpath] = true;
deps.push(info.subpath);
}
return deps;
Expand All @@ -38,7 +39,7 @@ module.exports.isomorphic = ['views', function (app, conf) {
return originModuleLoad(request, parent, isMain);
}
if (!frontendFactoryCache['frontend_' + request]) {
getDeps(request).forEach(dep => {
getDeps(request, frontendLoaded).forEach(dep => {
debuglog('require isomorphic script from', dep);
require(yog.ROOT_PATH + dep);
});
Expand All @@ -59,6 +60,7 @@ module.exports.isomorphic = ['views', function (app, conf) {

return {
cleanCache: function () {
frontendLoaded = {};
frontendCache = {};
frontendFactoryCache = {};
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/recv-reload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ function reloadIsomorphic() {
if (yog.plugins.isomorphic && yog.plugins.isomorphic.cleanCache) {
yog.plugins.isomorphic.cleanCache();
if (yog.conf.static) {
console.log('clean')
cleanCacheForFolder(yog.conf.static.staticPath);
} else {
cleanCacheForFolder(path.join(yog.ROOT_PATH, 'static'));
Expand Down Expand Up @@ -342,5 +341,5 @@ module.exports['recv-reload'].defaultConf = {
uploadTimeout: 30,
maxTarSize: '200mb',
onCacheClean: null,
lazyAppReload: true
lazyAppReload: false
};

0 comments on commit 024f873

Please sign in to comment.