Skip to content

Commit

Permalink
Merge pull request #406 from imajus/bugfix/event-handlers-reactive-loop
Browse files Browse the repository at this point in the history
Stop establishing unnecessary reactive dependencies
  • Loading branch information
StorytellerCZ authored Mar 31, 2023
2 parents c0d40bf + 9e57d5a commit 355b3bc
Showing 1 changed file with 11 additions and 7 deletions.
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

0 comments on commit 355b3bc

Please sign in to comment.