mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
re-implement UI._templateInstance()
This commit is contained in:
@@ -359,6 +359,16 @@ Blaze.getCurrentView = function (kind) {
|
||||
}
|
||||
};
|
||||
|
||||
// Gets the nearest ancestor view that corresponds to a template
|
||||
Blaze.getCurrentTemplateView = function () {
|
||||
var view = Blaze.getCurrentView();
|
||||
|
||||
while (view && ! view.template)
|
||||
view = view.parentView;
|
||||
|
||||
return view || null;
|
||||
};
|
||||
|
||||
Blaze.getParentView = function (view, kind) {
|
||||
var v = view.parentView;
|
||||
|
||||
|
||||
@@ -833,3 +833,7 @@ Hi there!
|
||||
<template name="spacebars_test_template_created_rendered_destroyed_each_sub">
|
||||
{{.}}
|
||||
</template>
|
||||
|
||||
<template name="spacebars_test_ui_getElementData">
|
||||
<span></span>
|
||||
</template>
|
||||
|
||||
@@ -2132,7 +2132,7 @@ Tinytest.add(
|
||||
);
|
||||
|
||||
Tinytest.add(
|
||||
"spacebars-tests - template_tests - access template instance from helper",
|
||||
"spacebars-tests - template_tests - UI._templateInstance from helper",
|
||||
function (test) {
|
||||
// Set a property on the template instance; check that it's still
|
||||
// there from a helper.
|
||||
@@ -2154,7 +2154,7 @@ Tinytest.add(
|
||||
);
|
||||
|
||||
Tinytest.add(
|
||||
"spacebars-tests - template_tests - access template instance from helper, " +
|
||||
"spacebars-tests - template_tests - UI._templateInstance from helper, " +
|
||||
"template instance is kept up-to-date",
|
||||
function (test) {
|
||||
var tmpl = Template.spacebars_test_template_instance_helper;
|
||||
|
||||
@@ -55,6 +55,14 @@ Template.__updateTemplateInstance = function (view) {
|
||||
return tmpl;
|
||||
};
|
||||
|
||||
UI._templateInstance = function () {
|
||||
var templateView = Blaze.getCurrentTemplateView();
|
||||
if (! templateView)
|
||||
throw new Error("No current template");
|
||||
|
||||
return Template.__updateTemplateInstance(templateView);
|
||||
};
|
||||
|
||||
Template.prototype.events = function (eventMap) {
|
||||
var template = this;
|
||||
template.__eventMaps = (template.__eventMaps || []);
|
||||
|
||||
Reference in New Issue
Block a user