Permalink
Browse files

Remove VIEW_PRESERVES_CONTEXT flag

Functionality can no longer be disabled.
  • Loading branch information...
wagenet committed Oct 20, 2012
1 parent f59a6f8 commit 710d1e1ab55a60edd259d8a3cd9c7467e1b50c41
View
@@ -81,7 +81,6 @@ task :test, [:suite] => :dist do |t, args|
"package=all&extendprototypes=true&nojshint=true",
"package=all&extendprototypes=true&jquery=git&nojshint=true",
"package=all&nocpdefaultcacheable=true&nojshint=true",
"package=all&noviewpreservescontext=true&nojshint=true",
"package=all&dist=build&nojshint=true"]
}
@@ -51,11 +51,7 @@ Ember.Handlebars.registerHelper('outlet', function(property, options) {
property = 'view';
}
if(Ember.VIEW_PRESERVES_CONTEXT) {
options.hash.currentViewBinding = "view.context." + property;
} else {
options.hash.currentViewBinding = "controller." + property;
}
options.hash.currentViewBinding = "view.context." + property;
return Ember.Handlebars.helpers.view.call(this, Ember.Handlebars.OutletView, options);
});
@@ -11,7 +11,6 @@ require("ember-handlebars");
var get = Ember.get, set = Ember.set;
var PARENT_VIEW_PATH = /^parentView\./;
var EmberHandlebars = Ember.Handlebars;
var VIEW_PRESERVES_CONTEXT = Ember.VIEW_PRESERVES_CONTEXT;
EmberHandlebars.ViewHelper = Ember.Object.create({
@@ -143,7 +142,7 @@ EmberHandlebars.ViewHelper = Ember.Object.create({
// We only want to override the `_context` computed property if there is
// no specified controller. See View#_context for more information.
if (VIEW_PRESERVES_CONTEXT && !newView.proto().controller && !newView.proto().controllerBinding && !viewOptions.controller && !viewOptions.controllerBinding) {
if (!newView.proto().controller && !newView.proto().controllerBinding && !viewOptions.controller && !viewOptions.controllerBinding) {
viewOptions._context = thisContext;
}
@@ -220,23 +220,13 @@ test("child views can be inserted using the {{view}} Handlebars helper", functio
templates: templates
});
if (Ember.VIEW_PRESERVES_CONTEXT) {
view.set('cruel', "cruel");
} else {
TemplateTests.LabelView.reopen({ cruel: "cruel" });
}
view.set('cruel', "cruel");
appendView();
ok(view.$("#hello-world:contains('Hello world!')").length, "The parent view renders its contents");
if (Ember.VIEW_PRESERVES_CONTEXT) {
ok(view.$("#child-view:contains('Goodbye cruel world!')").length === 1, "The child view renders its content once");
ok(view.$().text().match(/Hello world!.*Goodbye cruel world\!/), "parent view should appear before the child view");
} else {
ok(view.$("#child-view:contains('Goodbye cruel world?')").length === 1, "The child view renders its content once");
ok(view.$().text().match(/Hello world!.*Goodbye cruel world\?/), "parent view should appear before the child view");
}
ok(view.$("#child-view:contains('Goodbye cruel world!')").length === 1, "The child view renders its content once");
ok(view.$().text().match(/Hello world!.*Goodbye cruel world\!/), "parent view should appear before the child view");
});
test("should accept relative paths to views", function() {
@@ -281,23 +271,14 @@ test("child views can be inserted inside a bind block", function() {
templates: templates
});
if (Ember.VIEW_PRESERVES_CONTEXT) {
view.set('content', Ember.Object.create({ blah: "wot" }));
} else {
TemplateTests.BQView.reopen({ content: Ember.Object.create({ blah: "wot" }) });
}
view.set('content', Ember.Object.create({ blah: "wot" }));
appendView();
ok(view.$("#hello-world:contains('Hello world!')").length, "The parent view renders its contents");
if (Ember.VIEW_PRESERVES_CONTEXT) {
ok(view.$("blockquote").text().match(/Goodbye.*wot.*cruel.*world\!/), "The child view renders its content once");
ok(view.$().text().match(/Hello world!.*Goodbye.*wot.*cruel.*world\!/), "parent view should appear before the child view");
} else {
ok(view.$("blockquote").text().match(/Goodbye.*wot.*cruel.*world\?/), "The child view renders its content once");
ok(view.$().text().match(/Hello world!.*Goodbye.*wot.*cruel.*world\?/), "parent view should appear before the child view");
}
ok(view.$("blockquote").text().match(/Goodbye.*wot.*cruel.*world\!/), "The child view renders its content once");
ok(view.$().text().match(/Hello world!.*Goodbye.*wot.*cruel.*world\!/), "parent view should appear before the child view");
});
test("Ember.View should bind properties in the parent context", function() {
@@ -767,77 +748,46 @@ test("views set the template of their children to a passed block", function() {
ok(view.$('h1:has(span)').length === 1, "renders the passed template inside the parent template");
});
if (Ember.VIEW_PRESERVES_CONTEXT) {
test("views render their template in the context of the parent view's context", function() {
var templates = Ember.Object.create({
parent: Ember.Handlebars.compile('<h1>{{#with content}}{{#view}}{{firstName}} {{lastName}}{{/view}}{{/with}}</h1>')
});
view = Ember.View.create({
templates: templates,
templateName: 'parent',
content: {
firstName: "Lana",
lastName: "del Heeeyyyyyy"
}
});
appendView();
equal(view.$('h1').text(), "Lana del Heeeyyyyyy", "renders properties from parent context");
test("views render their template in the context of the parent view's context", function() {
var templates = Ember.Object.create({
parent: Ember.Handlebars.compile('<h1>{{#with content}}{{#view}}{{firstName}} {{lastName}}{{/view}}{{/with}}</h1>')
});
test("views make a view keyword available that allows template to reference view context", function() {
var templates = Ember.Object.create({
parent: Ember.Handlebars.compile('<h1>{{#with content}}{{#view subview}}{{view.firstName}} {{lastName}}{{/view}}{{/with}}</h1>')
});
view = Ember.View.create({
templates: templates,
templateName: 'parent',
content: {
subview: Ember.View.extend({
firstName: "Brodele"
}),
firstName: "Lana",
lastName: "del Heeeyyyyyy"
}
});
view = Ember.View.create({
templates: templates,
templateName: 'parent',
appendView();
equal(view.$('h1').text(), "Brodele del Heeeyyyyyy", "renders properties from parent context");
content: {
firstName: "Lana",
lastName: "del Heeeyyyyyy"
}
});
} else {
test("should pass hash arguments to the view object", function() {
TemplateTests.bindTestObject = Ember.Object.create({
bar: 'bat'
});
TemplateTests.HashArgTemplateView = Ember.View.extend({
});
Ember.run(function() {
view = Ember.View.create({
template: Ember.Handlebars.compile('{{#view TemplateTests.HashArgTemplateView fooBinding="TemplateTests.bindTestObject.bar"}}{{foo}}{{/view}}')
});
appendView();
});
appendView();
equal(view.$('h1').text(), "Lana del Heeeyyyyyy", "renders properties from parent context");
});
equal(view.$().text(), "bat", "prints initial bound value");
test("views make a view keyword available that allows template to reference view context", function() {
var templates = Ember.Object.create({
parent: Ember.Handlebars.compile('<h1>{{#with content}}{{#view subview}}{{view.firstName}} {{lastName}}{{/view}}{{/with}}</h1>')
});
Ember.run(function() {
set(TemplateTests.bindTestObject, 'bar', 'brains');
});
view = Ember.View.create({
templates: templates,
templateName: 'parent',
equal(view.$().text(), "brains", "prints updated bound value");
content: {
subview: Ember.View.extend({
firstName: "Brodele"
}),
firstName: "Lana",
lastName: "del Heeeyyyyyy"
}
});
}
appendView();
equal(view.$('h1').text(), "Brodele del Heeeyyyyyy", "renders properties from parent context");
});
test("should warn if setting a template on a view with a templateName already specified", function() {
view = Ember.View.create({
@@ -2304,9 +2254,7 @@ test("should update bound values after view's parent is removed and then re-appe
})
});
var targetView = Ember.VIEW_PRESERVES_CONTEXT ? parentView : parentView.get('testView');
targetView.setProperties({
parentView.setProperties({
showStuff: true,
boundValue: "foo"
});
@@ -2318,29 +2266,29 @@ test("should update bound values after view's parent is removed and then re-appe
equal(Ember.$.trim(view.$().text()), "foo");
Ember.run(function() {
set(targetView, 'showStuff', false);
set(parentView, 'showStuff', false);
});
equal(Ember.$.trim(view.$().text()), "Not true.");
Ember.run(function() {
set(targetView, 'showStuff', true);
set(parentView, 'showStuff', true);
});
equal(Ember.$.trim(view.$().text()), "foo");
Ember.run(function() {
parentView.remove();
set(targetView, 'showStuff', false);
set(parentView, 'showStuff', false);
});
Ember.run(function() {
set(targetView, 'showStuff', true);
set(parentView, 'showStuff', true);
});
Ember.run(function() {
parentView.appendTo('#qunit-fixture');
});
Ember.run(function() {
set(targetView, 'boundValue', "bar");
set(parentView, 'boundValue', "bar");
});
equal(Ember.$.trim(view.$().text()), "bar");
});
@@ -270,72 +270,68 @@ test("it works with the controller keyword", function() {
equal(view.$().text(), "foobarbaz");
});
if (Ember.VIEW_PRESERVES_CONTEXT) {
module("{{#each foo in bar}}");
module("{{#each foo in bar}}");
test("#each accepts a name binding and does not change the context", function() {
view = Ember.View.create({
template: templateFor("{{#each item in items}}{{title}} {{item}}{{/each}}"),
title: "My Cool Each Test",
items: Ember.A([1, 2])
});
append(view);
equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2");
test("#each accepts a name binding and does not change the context", function() {
view = Ember.View.create({
template: templateFor("{{#each item in items}}{{title}} {{item}}{{/each}}"),
title: "My Cool Each Test",
items: Ember.A([1, 2])
});
test("#each accepts a name binding and can display child properties", function() {
view = Ember.View.create({
template: templateFor("{{#each item in items}}{{title}} {{item.name}}{{/each}}"),
title: "My Cool Each Test",
items: Ember.A([{ name: 1 }, { name: 2 }])
});
append(view);
append(view);
equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2");
});
equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2");
test("#each accepts a name binding and can display child properties", function() {
view = Ember.View.create({
template: templateFor("{{#each item in items}}{{title}} {{item.name}}{{/each}}"),
title: "My Cool Each Test",
items: Ember.A([{ name: 1 }, { name: 2 }])
});
test("#each accepts 'this' as the right hand side", function() {
view = Ember.View.create({
template: templateFor("{{#each item in this}}{{view.title}} {{item.name}}{{/each}}"),
title: "My Cool Each Test",
controller: Ember.A([{ name: 1 }, { name: 2 }])
});
append(view);
append(view);
equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2");
});
equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2");
test("#each accepts 'this' as the right hand side", function() {
view = Ember.View.create({
template: templateFor("{{#each item in this}}{{view.title}} {{item.name}}{{/each}}"),
title: "My Cool Each Test",
controller: Ember.A([{ name: 1 }, { name: 2 }])
});
test("views inside #each preserve the new context", function() {
var controller = Ember.A([ { name: "Adam" }, { name: "Steve" } ]);
append(view);
view = Ember.View.create({
controller: controller,
template: templateFor('{{#each controller}}{{#view}}{{name}}{{/view}}{{/each}}')
});
equal(view.$().text(), "My Cool Each Test 1My Cool Each Test 2");
});
append(view);
test("views inside #each preserve the new context", function() {
var controller = Ember.A([ { name: "Adam" }, { name: "Steve" } ]);
equal(view.$().text(), "AdamSteve");
view = Ember.View.create({
controller: controller,
template: templateFor('{{#each controller}}{{#view}}{{name}}{{/view}}{{/each}}')
});
test("controller is assignable inside an #each", function() {
var controller = Ember.ArrayController.create({
content: Ember.A([ { name: "Adam" }, { name: "Steve" } ])
});
append(view);
view = Ember.View.create({
controller: controller,
template: templateFor('{{#each itemController in this}}{{#view controllerBinding="itemController"}}{{name}}{{/view}}{{/each}}')
});
equal(view.$().text(), "AdamSteve");
});
append(view);
test("controller is assignable inside an #each", function() {
var controller = Ember.ArrayController.create({
content: Ember.A([ { name: "Adam" }, { name: "Steve" } ])
});
equal(view.$().text(), "AdamSteve");
view = Ember.View.create({
controller: controller,
template: templateFor('{{#each itemController in this}}{{#view controllerBinding="itemController"}}{{name}}{{/view}}{{/each}}')
});
}
append(view);
equal(view.$().text(), "AdamSteve");
});
@@ -14,18 +14,14 @@ module("Handlebars {{#if}} and {{#unless}} helpers", {
}
});
if (Ember.VIEW_PRESERVES_CONTEXT) {
test("unless should keep the current context (#784)", function() {
view = Ember.View.create({
o: Ember.Object.create({foo: '42'}),
test("unless should keep the current context (#784)", function() {
view = Ember.View.create({
o: Ember.Object.create({foo: '42'}),
template: Ember.Handlebars.compile('{{#with o}}{{#view Ember.View}}{{#unless view.doesNotExist}}foo: {{foo}}{{/unless}}{{/view}}{{/with}}')
});
appendView(view);
equal(view.$().text(), 'foo: 42');
template: Ember.Handlebars.compile('{{#with o}}{{#view Ember.View}}{{#unless view.doesNotExist}}foo: {{foo}}{{/unless}}{{/view}}{{/with}}')
});
}
appendView(view);
equal(view.$().text(), 'foo: 42');
});
Oops, something went wrong.

0 comments on commit 710d1e1

Please sign in to comment.