Skip to content

Commit 3b672bb

Browse files
committed
Fix routes cache when the framework performs uninstall.
1 parent 25f82c6 commit 3b672bb

1 file changed

Lines changed: 30 additions & 18 deletions

File tree

index.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ Framework.prototype.useConfig = function(name) {
880880
* Sort all routes
881881
* @return {Framework}
882882
*/
883-
Framework.prototype._routesSort = function(type) {
883+
Framework.prototype.$routesSort = function(type) {
884884

885885
var self = this;
886886

@@ -922,6 +922,12 @@ Framework.prototype._routesSort = function(type) {
922922
route.isUNIQUE = tmp == null;
923923
});
924924

925+
// Clears cache
926+
Object.keys(F.temporary.other).forEach(function(key) {
927+
if (key[0] === '#')
928+
F.temporary.other[key] = undefined;
929+
});
930+
925931
return self;
926932
};
927933

@@ -1816,7 +1822,7 @@ Framework.prototype.web = Framework.prototype.route = function(url, funcExecute,
18161822

18171823
// Appends cors route
18181824
isCORS && F.cors(urlcache, corsflags);
1819-
!_controller && self._routesSort(1);
1825+
!_controller && self.$routesSort(1);
18201826

18211827
return self;
18221828
};
@@ -2381,7 +2387,7 @@ Framework.prototype.websocket = function(url, funcInitialize, flags, length) {
23812387
});
23822388

23832389
F.emit('route', 'websocket', F.routes.websockets[F.routes.websockets.length - 1]);
2384-
!_controller && F._routesSort(2);
2390+
!_controller && F.$routesSort(2);
23852391
return F;
23862392
};
23872393

@@ -2867,7 +2873,7 @@ Framework.prototype.$load = function(types, targetdirectory) {
28672873
arr.forEach((item) => self.install('component', item.name, item.filename, undefined, undefined, undefined));
28682874
}
28692875

2870-
self._routesSort();
2876+
self.$routesSort();
28712877

28722878
if (!types || types.indexOf('dependencies') !== -1)
28732879
self._configure_dependencies();
@@ -3785,7 +3791,7 @@ Framework.prototype.install_make = function(key, name, obj, options, callback, s
37853791
F.routes.files[i].controller = id;
37863792
}
37873793

3788-
F._routesSort();
3794+
F.$routesSort();
37893795
_controller = '';
37903796

37913797
if (!skipEmit) {
@@ -3881,7 +3887,6 @@ Framework.prototype.uninstall = function(type, name, options, skipEmit) {
38813887
F.routes.web = F.routes.web.remove('owner', id);
38823888
F.routes.files = F.routes.files.remove('owner', id);
38833889
F.routes.websockets = F.routes.websockets.remove('owner', id);
3884-
38853890
typeof(obj.uninstall) === 'function' && obj.uninstall(options, name);
38863891

38873892
if (type === 'model')
@@ -3890,7 +3895,7 @@ Framework.prototype.uninstall = function(type, name, options, skipEmit) {
38903895
delete F.sources[name];
38913896

38923897
delete F.dependencies[type + '.' + name];
3893-
F._routesSort();
3898+
F.$routesSort();
38943899

38953900
} else if (type === 'module' || type === 'controller') {
38963901

@@ -3919,17 +3924,22 @@ Framework.prototype.uninstall = function(type, name, options, skipEmit) {
39193924
delete F.controllers[name];
39203925
}
39213926

3922-
F._routesSort();
3927+
F.$routesSort();
39233928

39243929
} else if (type === 'component') {
39253930

3931+
if (!F.components.instances[name])
3932+
return F;
3933+
39263934
obj = F.components.instances[name];
3935+
39273936
if (obj) {
39283937
F.routes.web = F.routes.web.remove('owner', id);
39293938
F.routes.files = F.routes.files.remove('owner', id);
39303939
F.routes.websockets = F.routes.websockets.remove('owner', id);
39313940
obj.uninstall && obj.uninstall(options, name);
3932-
F._routesSort();
3941+
F.$routesSort();
3942+
delete F.components.instances[name];
39333943
}
39343944

39353945
delete F.components.instances[name];
@@ -4844,8 +4854,10 @@ Framework.prototype.responseStatic = function(req, res, done) {
48444854

48454855
// is isomorphic?
48464856
if (filename[0] !== '#') {
4847-
if (F.components.has && F.components[req.extension] && req.uri.pathname === F.config['static-url-components'] + req.extension)
4857+
if (F.components.has && F.components[req.extension] && req.uri.pathname === F.config['static-url-components'] + req.extension) {
4858+
res.noCompress = true;
48484859
filename = F.path.temp('components.' + req.extension);
4860+
}
48494861
F.responseFile(req, res, filename, undefined, undefined, done);
48504862
return F;
48514863
}
@@ -8515,7 +8527,7 @@ Framework.prototype._configure = function(arr, rewrite) {
85158527
Framework.prototype.routeScript = function(name, theme) {
85168528
if (!name.endsWith('.js'))
85178529
name += '.js';
8518-
return F._routeStatic(name, F.config['static-url-script'], theme);
8530+
return F.$routeStatic(name, F.config['static-url-script'], theme);
85198531
};
85208532

85218533
/**
@@ -8524,30 +8536,30 @@ Framework.prototype.routeScript = function(name, theme) {
85248536
* @return {String}
85258537
*/
85268538
Framework.prototype.routeStyle = function(name, theme) {
8527-
return F._routeStatic(name + (name.endsWith('.css') ? '' : '.css'), F.config['static-url-style'], theme);
8539+
return F.$routeStatic(name + (name.endsWith('.css') ? '' : '.css'), F.config['static-url-style'], theme);
85288540
};
85298541

85308542
Framework.prototype.routeImage = function(name, theme) {
8531-
return F._routeStatic(name, F.config['static-url-image'], theme);
8543+
return F.$routeStatic(name, F.config['static-url-image'], theme);
85328544
};
85338545

85348546
Framework.prototype.routeVideo = function(name, theme) {
8535-
return F._routeStatic(name, F.config['static-url-video'], theme);
8547+
return F.$routeStatic(name, F.config['static-url-video'], theme);
85368548
};
85378549

85388550
Framework.prototype.routeFont = function(name, theme) {
8539-
return F._routeStatic(name, F.config['static-url-font'], theme);
8551+
return F.$routeStatic(name, F.config['static-url-font'], theme);
85408552
};
85418553

85428554
Framework.prototype.routeDownload = function(name, theme) {
8543-
return F._routeStatic(name, F.config['static-url-download'], theme);
8555+
return F.$routeStatic(name, F.config['static-url-download'], theme);
85448556
};
85458557

85468558
Framework.prototype.routeStatic = function(name, theme) {
8547-
return F._routeStatic(name, F.config['static-url'], theme);
8559+
return F.$routeStatic(name, F.config['static-url'], theme);
85488560
};
85498561

8550-
Framework.prototype._routeStatic = function(name, directory, theme) {
8562+
Framework.prototype.$routeStatic = function(name, directory, theme) {
85518563
var key = name + directory + '$' + theme;
85528564
var val = F.temporary.other[key];
85538565
if (RELEASE && val)

0 commit comments

Comments
 (0)