mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Fix the bug of firing a rendered callback when it was added too late
This commit is contained in:
@@ -98,14 +98,17 @@ Template.prototype.onDestroyed = function (cb) {
|
||||
this._callbacks.destroyed.push(cb);
|
||||
};
|
||||
|
||||
Template.prototype._fireCallbacks = function (template, which) {
|
||||
Template.prototype._getCallbacks = function (which) {
|
||||
var self = this;
|
||||
var callbacks = self[which] ? [self[which]] : [];
|
||||
// Fire all callbacks added with the new API (Template.onRendered())
|
||||
// as well as the old-style callback (e.g. Template.rendered) for
|
||||
// backwards-compatibility.
|
||||
callbacks = callbacks.concat(self._callbacks[which]);
|
||||
return callbacks;
|
||||
};
|
||||
|
||||
var fireCallbacks = function (callbacks, template) {
|
||||
for (var i = 0, N = callbacks.length; i < N; i++) {
|
||||
callbacks[i].call(template);
|
||||
}
|
||||
@@ -177,8 +180,9 @@ Template.prototype.constructView = function (contentFunc, elseFunc) {
|
||||
* @locus Client
|
||||
* @deprecated in 1.1
|
||||
*/
|
||||
var createdCallbacks = self._getCallbacks('created');
|
||||
view.onViewCreated(function () {
|
||||
self._fireCallbacks(view.templateInstance(), 'created');
|
||||
fireCallbacks(createdCallbacks, view.templateInstance());
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -189,8 +193,9 @@ Template.prototype.constructView = function (contentFunc, elseFunc) {
|
||||
* @locus Client
|
||||
* @deprecated in 1.1
|
||||
*/
|
||||
var renderedCallbacks = self._getCallbacks('rendered');
|
||||
view.onViewReady(function () {
|
||||
self._fireCallbacks(view.templateInstance(), 'rendered');
|
||||
fireCallbacks(renderedCallbacks, view.templateInstance());
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -201,8 +206,9 @@ Template.prototype.constructView = function (contentFunc, elseFunc) {
|
||||
* @locus Client
|
||||
* @deprecated in 1.1
|
||||
*/
|
||||
var destroyedCallbacks = self._getCallbacks('destroyed');
|
||||
view.onViewDestroyed(function () {
|
||||
self._fireCallbacks(view.templateInstance(), 'destroyed');
|
||||
fireCallbacks(destroyedCallbacks, view.templateInstance());
|
||||
});
|
||||
|
||||
return view;
|
||||
|
||||
@@ -1252,9 +1252,12 @@ Tinytest.add('spacebars-tests - template_tests - inclusion helpers are isolated'
|
||||
}});
|
||||
|
||||
var div = renderToDiv(tmpl);
|
||||
subtmplCopy.rendered = function () {
|
||||
subtmplCopy.rendered = function () {
|
||||
test.fail("shouldn't re-render when same value returned from helper");
|
||||
};
|
||||
subtmplCopy.onRendered(function () {
|
||||
test.fail("shouldn't re-render when same value returned from helper");
|
||||
});
|
||||
|
||||
dep.changed();
|
||||
Tracker.flush({_throwFirstError: true}); // `subtmplCopy.rendered` not called
|
||||
|
||||
Reference in New Issue
Block a user