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

Stop establishing unnecessary reactive dependencies #406

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Changes from all commits
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
18 changes: 11 additions & 7 deletions packages/blaze/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,18 @@ Template.prototype.events = function (eventMap) {
eventMap2[k] = (function (k, v) {
return function (event /*, ...*/) {
var view = this; // passed by EventAugmenter
var data = Blaze.getData(event.currentTarget);
if (data == null) data = {};
var args = Array.prototype.slice.call(arguments);
var tmplInstanceFunc = Blaze._bind(view.templateInstance, view);
args.splice(1, 0, tmplInstanceFunc());

return Template._withTemplateInstanceFunc(tmplInstanceFunc, function () {
return v.apply(data, args);
// Exiting the current computation to avoid creating unnecessary
// and unexpected reactive dependencies with Templates data
// or any other reactive dependencies defined in event handlers
return Tracker.nonreactive(function () {
var data = Blaze.getData(event.currentTarget);
if (data == null) data = {};
var tmplInstanceFunc = Blaze._bind(view.templateInstance, view);
args.splice(1, 0, tmplInstanceFunc());
return Template._withTemplateInstanceFunc(tmplInstanceFunc, function () {
return v.apply(data, args);
});
});
};
})(k, eventMap[k]);
Expand Down