-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support of hot templates reconnection #28
Comments
Teacup doesn't connect to anything. It is just a function that creates On Sun, Sep 22, 2013 at 5:34 AM, isglazunov notifications@github.comwrote:
|
Thank you. Probably my fault. I apologize for my English of Google translate. Or should make a connection to express in a separate module. PS TeaCup - genius and simple solution. I very much want to do it / him for one chip, but prevents a cold connection files. |
@isglazunov teacup doesn't support the I spent a little time thinking about what support would take a while back. The Consolidate.js Teacup adapter has a half-baked implementation. The two big problems I remember were:
If you find a solution that feel general purpose and robust, I'd love to pull it into teacup. A less general solution (like only supporting templates without require statements) could also be useful, and probably belongs in a separate module. |
I chenge file teacup/lib/express.js // Generated by CoffeeScript 1.6.3
(function() {
var CoffeeScript;
CoffeeScript = require('coffee-script');
module.exports = {
renderFile: function(path, options, callback) {
var err;
try {
console.log(options.app); // options.app is undefined in express 3.4.0
if (!options.cache) { // but options.cache is boolean
delete require.cache[require.resolve(path)];
}
return callback(null, require(path)(options));
} catch (_error) {
err = _error;
return callback(err);
}
}
};
}).call(this); It work! |
I suggest to change the strategy. Teacup = require ("teacup")
teacup = Teacup cache: false Make |
If you want, here is a test room. |
The problem I anticipate looks like:
How do I make sure '/' updates when I make changes to This might be easier to communicate with some automated tests and a pull request. |
Earlier I wrote about the |
looks like this was already implemented? This issue can probably be closed, right? module.exports =
renderFile: (path, options, callback) ->
try
# If express app does not have view cache enabled, clear the require cache
if options.app? and not options.app.enabled('view cache')
delete require.cache[require.resolve path]
callback null, require(path)(options)
catch err
callback err |
I added a failing test on the branch bust-cache to illustrate the case described above where the implemented solution breaks down. Feels error prone to me, so I've left the issue open, but totally depends how you use Teacup. If you don't require template helpers, then yes, the issue is solved for you. With templates split across files I still prefer more general solutions like nodemon or node-dev. |
Perhaps you should have a look at http://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate - I adapted the code from one of the answers and published it as 'require-clean' - it seems to be working for uRequire's support for Teacup refreshing templates. |
Thanks for the heads up @anodynos. I hadn't seen In the example above, if two templates used |
I guess you could: find recursively which modules have module A as a child, then these are A's parents. But you'll have to go through the whole cache recursively which would be slowish. Also you would also need to clean all parent's parents and so on. But I wonder if that parent reseting is really needed. Any time module A needs to load, it needs to load its self fresh along with all its children ( But why do we need to refresh the parent's of A, since the parent will reset it self & children when the parent actually loads (i.e when '/' is requested ) ? |
So we'd require the template and all its helpers clean on every request, even when nothing has changed... Sounds like that'd work! I was getting hung up on change tracking but we may not need it at all. Something like: renderFile: (path, options, callback) ->
try
# If express app does not have view cache enabled, clear the require cache
if options.app?.enabled('view cache')
template = require path
else
requireClean = require 'require-clean'
template = requireClean path
callback null, template(options)
catch err
callback err |
Tracking changes to the template and its reconnection if changed
Maybe I did not understand something and it's already implemented?
The text was updated successfully, but these errors were encountered: