Skip to content
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

Update dependencies in blaze-hot #432

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/blaze-hot/hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function patchTemplate(Template) {
Template.registerHelper = function (name, func) {
func[SourceModule] = currentModule.id;
oldRegisterHelper(name, func);
}
};

const oldOnCreated = Template.prototype.onCreated;
Template.prototype.onCreated = function (cb) {
Expand All @@ -20,7 +20,7 @@ function patchTemplate(Template) {
}

return oldOnCreated.call(this, cb);
}
};

const oldOnRendered = Template.prototype.onRendered;
Template.prototype.onRendered = function (cb) {
Expand All @@ -29,7 +29,7 @@ function patchTemplate(Template) {
}

return oldOnRendered.call(this, cb);
}
};

const oldOnDestroyed = Template.prototype.onDestroyed;
Template.prototype.onDestroyed = function (cb) {
Expand All @@ -38,31 +38,31 @@ function patchTemplate(Template) {
}

return oldOnDestroyed.call(this, cb);
}
};

const oldHelpers = Template.prototype.helpers;
Template.prototype.helpers = function (dict) {
if (typeof dict === 'object') {
for (var k in dict) {
for (let k in dict) {
Copy link
Collaborator

@jankapunkt jankapunkt Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: add a TODO note, that we should change this in the future to a solution that won't use for..in

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can do this in this PR, I have fixed that in other PRs.

if (dict[k]) {
dict[k][SourceModule] = currentModule.id;
}
}
}

return oldHelpers.call(this, dict);
}
};

const oldEvents = Template.prototype.events;
Template.prototype.events = function (eventMap) {
const result = oldEvents.call(this, eventMap);
this.__eventMaps[this.__eventMaps.length - 1][SourceModule] = currentModule.id;
return result;
}
};
}

function cleanTemplate(template, moduleId) {
let usedModule = false
let usedModule = false;
if (!template || !Blaze.isTemplate(template)) {
return usedModule;
}
Expand All @@ -71,7 +71,7 @@ function cleanTemplate(template, moduleId) {
for (let i = array.length - 1; i >= 0; i--) {
let item = array[i];
if (item && item[SourceModule] === moduleId) {
usedModule = true
usedModule = true;
array.splice(i, 1);
}
}
Expand All @@ -84,12 +84,12 @@ function cleanTemplate(template, moduleId) {

Object.keys(template.__helpers).forEach(key => {
if (template.__helpers[key] && template.__helpers[key][SourceModule] === moduleId) {
usedModule = true
usedModule = true;
delete template.__helpers[key];
}
});

return usedModule
return usedModule;
}

function shouldAccept(module) {
Expand Down Expand Up @@ -120,7 +120,7 @@ if (module.hot) {
module.hot.accept();
module.hot.dispose(() => {
Object.keys(Templates).forEach(templateName => {
let template = Templates[templateName]
let template = Templates[templateName];
let usedByModule = cleanTemplate(template, module.id);
if (usedByModule) {
Template._applyHmrChanges(templateName);
Expand All @@ -134,7 +134,7 @@ if (module.hot) {
});
});
}
currentModule = previousModule
currentModule = previousModule;
}
});
}
10 changes: 5 additions & 5 deletions packages/blaze-hot/package.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Package.describe({
name: 'blaze-hot',
summary: "Update files using Blaze's API with HMR",
version: '1.1.1',
version: '1.1.2',
git: 'https://github.com/meteor/blaze.git',
documentation: null,
debugOnly: true
});

Package.onUse(function (api) {
api.use('modules@0.16.0');
api.use('ecmascript@0.15.1');
api.use('modules@0.19.0');
api.use('ecmascript@0.16.7');
api.use('blaze@2.7.1');
api.use('templating-runtime@1.6.0');
api.use('hot-module-replacement@0.2.0', { weak: true });
api.use('templating-runtime@1.6.3');
api.use('hot-module-replacement@0.5.3', { weak: true });

api.addFiles('hot.js', 'client');
api.addFiles('update-templates.js', 'client');
Expand Down
8 changes: 4 additions & 4 deletions packages/blaze-hot/update-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Template.prototype.constructView = function () {
}

return view;
}
};

let updateRootViews = Template._applyHmrChanges;

Expand All @@ -59,8 +59,8 @@ Template._applyHmrChanges = function (templateName = UpdateAll) {
}

timeout = setTimeout(() => {
for (var i = 0; i < Template.__pendingReplacement.length; i++) {
delete Template[Template.__pendingReplacement[i]]
for (let i = 0; i < Template.__pendingReplacement.length; i++) {
delete Template[Template.__pendingReplacement[i]];
}

Template.__pendingReplacement = [];
Expand Down Expand Up @@ -161,4 +161,4 @@ Template._applyHmrChanges = function (templateName = UpdateAll) {
}
});
});
}
};