Make it so that Handlebars partials get reloaded automatically
This commit is contained in:
parent
93b55df045
commit
dda38b6695
3 changed files with 45 additions and 11 deletions
30
module/hooks/hotReload.js
Normal file
30
module/hooks/hotReload.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Hooks.on(`hotReload`, async (data) => {
|
||||
if (data.extension !== 'hbs') {
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!hbs.partials.some(p => data.path.endsWith(p))) {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
// Compile the new template data.
|
||||
let template;
|
||||
try {
|
||||
template = Handlebars.compile(data.content);
|
||||
} catch (err) {
|
||||
return console.error(err);
|
||||
};
|
||||
|
||||
// Re-register our new partial template & cache it.
|
||||
const templateName = `dotdungeon.${data.path.split("/").pop().replace(".hbs", "")}`;
|
||||
Handlebars.registerPartial(templateName, template);
|
||||
_templateCache[templateName] = template;
|
||||
|
||||
// Re-render open windows
|
||||
for (const window of ui.windows) {
|
||||
window.render(true);
|
||||
};
|
||||
|
||||
return false;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue