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

[CLEANUP beta] Remove globals lookup from templates. #11897

Merged
merged 1 commit into from
Jul 25, 2015
Merged
Show file tree
Hide file tree
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
14 changes: 0 additions & 14 deletions packages/ember-htmlbars/lib/hooks/get-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
@submodule ember-htmlbars
*/

import Ember from 'ember-metal/core';
import { isGlobal } from 'ember-metal/path_cache';
import ProxyStream from 'ember-metal/streams/proxy-stream';

export default function getRoot(scope, key) {
if (key === 'this') {
return [scope.self];
} else if (key === 'hasBlock') {
return [!!scope.blocks.default];
} else if (key === 'hasBlockParams') {
return [!!(scope.blocks.default && scope.blocks.default.arity)];
} else if (isGlobal(key) && Ember.lookup[key]) {
return [getGlobal(key)];
} else if (key in scope.locals) {
return [scope.locals[key]];
} else {
Expand All @@ -38,11 +32,3 @@ function getKey(scope, key) {
return scope.attrs[key];
}
}

function getGlobal(name) {
Ember.deprecate('Global lookup of ' + name + ' from a Handlebars template is deprecated.', false, { id: 'ember-htmlbars.get-global', until: '3.0.0' });

// This stream should be memoized, but this path is deprecated and
// will be removed soon so it's not worth the trouble.
return new ProxyStream(Ember.lookup[name], name);
}
20 changes: 0 additions & 20 deletions packages/ember-htmlbars/tests/compat/make_bound_helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,6 @@ QUnit.test('bound helpers should support keywords', function() {
equal(view.$().text(), 'AB', 'helper output is correct');
});

QUnit.test('bound helpers should support global paths [DEPRECATED]', function() {
expectDeprecationInHTMLBars();

helper('capitalize', function(value) {
return value.toUpperCase();
});

Ember.lookup = { Text: 'ab' };

view = EmberView.create({
template: compile('{{capitalize Text}}')
});

expectDeprecation(function() {
runAppend(view);
}, /Global lookup of Text from a Handlebars template is deprecated/);

equal(view.$().text(), 'AB', 'helper output is correct');
});

QUnit.test('bound helper should support this keyword', function() {
expectDeprecationInHTMLBars();

Expand Down
20 changes: 0 additions & 20 deletions packages/ember-htmlbars/tests/helpers/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,6 @@ QUnit.test('Collection views that specify an example view class have their child
ok(firstGrandchild(view).isCustom, 'uses the example view class');
});

QUnit.test('itemViewClass works in the #collection helper with a global (DEPRECATED)', function() {
TemplateTests.ExampleItemView = EmberView.extend({
isAlsoCustom: true
});

view = EmberView.create({
exampleController: ArrayProxy.create({
content: A(['alpha'])
}),
template: compile('{{#collection content=view.exampleController itemViewClass=TemplateTests.ExampleItemView}}beta{{/collection}}')
});

var deprecation = /Global lookup of TemplateTests from a Handlebars template is deprecated/;
expectDeprecation(function() {
runAppend(view);
}, deprecation);

ok(firstGrandchild(view).isAlsoCustom, 'uses the example view class specified in the #collection helper');
});

QUnit.test('itemViewClass works in the #collection helper with a property', function() {
var ExampleItemView = EmberView.extend({
isAlsoCustom: true
Expand Down
40 changes: 2 additions & 38 deletions packages/ember-htmlbars/tests/helpers/each_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,6 @@ QUnit.test('it defers all normalization of itemView names to the resolver', func
assertText(view, 'itemView:Steve HoltitemView:Annabelle');
});

QUnit.test('it supports {{itemViewClass=}} with global (DEPRECATED)', function() {
expectDeprecation(() => {
view = EmberView.create({
template: compile('{{each view.people itemViewClass=MyView}}'),
people: people,
container: container
});
}, /Using 'itemViewClass' with '{{each}}'/);

var deprecation = /Global lookup of MyView from a Handlebars template is deprecated/;

expectDeprecation(function() {
runAppend(view);
}, deprecation);

assertText(view, 'Steve HoltAnnabelle');
});

QUnit.test('it supports {{itemViewClass=}} via container', function() {
expectDeprecation(() => {
view = EmberView.create({
Expand All @@ -323,7 +305,7 @@ QUnit.test('it supports {{itemViewClass=}} via container', function() {
QUnit.test('it supports {{itemViewClass=}} with each view tagName (DEPRECATED)', function() {
expectDeprecation(() => {
view = EmberView.create({
template: compile('{{each view.people itemViewClass=MyView tagName="ul"}}'),
template: compile('{{each view.people itemViewClass="my-view" tagName="ul"}}'),
people: people,
container: container
});
Expand Down Expand Up @@ -414,24 +396,6 @@ QUnit.test('it defers all normalization of emptyView names to the resolver', fun
assertText(view, 'emptyView:sad panda');
});

QUnit.test('it supports {{emptyViewClass=}} with global (DEPRECATED)', function() {
expectDeprecation(() => {
view = EmberView.create({
template: compile('{{each view.people emptyViewClass=MyEmptyView}}'),
people: A(),
container: container
});
}, /Using 'emptyViewClass' with '{{each}}'/);

var deprecation = /Global lookup of MyEmptyView from a Handlebars template is deprecated/;

expectDeprecation(function() {
runAppend(view);
}, deprecation);

assertText(view, 'I\'m empty');
});

QUnit.test('it supports {{emptyViewClass=}} via container', function() {
expectDeprecation(() => {
view = EmberView.create({
Expand All @@ -449,7 +413,7 @@ QUnit.test('it supports {{emptyViewClass=}} via container', function() {
QUnit.test('it supports {{emptyViewClass=}} with tagName (DEPRECATED)', function() {
expectDeprecation(() => {
view = EmberView.create({
template: compile('{{each view.people emptyViewClass=MyEmptyView tagName="b"}}'),
template: compile('{{each view.people emptyViewClass="my-empty-view" tagName="b"}}'),
people: A(),
container: container
});
Expand Down
127 changes: 0 additions & 127 deletions packages/ember-htmlbars/tests/helpers/view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ComponentLookup from 'ember-views/component_lookup';
import run from 'ember-metal/run_loop';
import jQuery from 'ember-views/system/jquery';
import TextField from 'ember-views/views/text_field';
import Namespace from 'ember-runtime/system/namespace';
import EmberObject from 'ember-runtime/system/object';
import ContainerView from 'ember-views/views/container_view';
import SafeString from 'htmlbars-util/safe-string';
Expand Down Expand Up @@ -130,27 +129,6 @@ QUnit.test('By default, without a container, EmberView is used', function() {
ok(jQuery('#qunit-fixture').html().toUpperCase().match(/<SPAN/), 'contains view with span');
});

QUnit.test('View lookup - App.FuView (DEPRECATED)', function() {
Ember.lookup = {
App: {
FuView: viewClass({
elementId: 'fu',
template: compile('bro')
})
}
};

view = viewClass({
template: compile('{{view App.FuView}}')
}).create();

expectDeprecation(function() {
runAppend(view);
}, /Global lookup of App from a Handlebars template is deprecated./);

equal(jQuery('#fu').text(), 'bro');
});

QUnit.test('View lookup - \'fu\'', function() {
var FuView = viewClass({
elementId: 'fu',
Expand Down Expand Up @@ -848,46 +826,6 @@ QUnit.test('{{view}} should be able to point to a local view', function() {
equal(view.$().text(), 'common', 'tries to look up view name locally');
});

QUnit.test('{{view}} should evaluate class bindings set to global paths DEPRECATED', function() {
var App;

run(function() {
lookup.App = App = Namespace.create({
isApp: true,
isGreat: true,
directClass: 'app-direct',
isEnabled: true
});
});

view = EmberView.create({
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled:enabled:disabled"}}')
});

expectDeprecation(function() {
runAppend(view);
});

ok(view.$('input').hasClass('unbound'), 'sets unbound classes directly');
ok(view.$('input').hasClass('great'), 'evaluates classes bound to global paths');
ok(view.$('input').hasClass('app-direct'), 'evaluates classes bound directly to global paths');
ok(view.$('input').hasClass('is-app'), 'evaluates classes bound directly to booleans in global paths - dasherizes and sets class when true');
ok(view.$('input').hasClass('enabled'), 'evaluates ternary operator in classBindings');
ok(!view.$('input').hasClass('disabled'), 'evaluates ternary operator in classBindings');

run(function() {
App.set('isApp', false);
App.set('isEnabled', false);
});

ok(!view.$('input').hasClass('is-app'), 'evaluates classes bound directly to booleans in global paths - removes class when false');
ok(!view.$('input').hasClass('enabled'), 'evaluates ternary operator in classBindings');
ok(view.$('input').hasClass('disabled'), 'evaluates ternary operator in classBindings');

runDestroy(lookup.App);
});

QUnit.test('{{view}} should evaluate class bindings set in the current context', function() {
view = EmberView.create({
isView: true,
Expand Down Expand Up @@ -917,71 +855,6 @@ QUnit.test('{{view}} should evaluate class bindings set in the current context',
ok(view.$('input').hasClass('disabled'), 'evaluates ternary operator in classBindings');
});

QUnit.test('{{view}} should evaluate class bindings set with either classBinding or classNameBindings from globals DEPRECATED', function() {
var App;

run(function() {
lookup.App = App = Namespace.create({
isGreat: true,
isEnabled: true
});
});

view = EmberView.create({
textField: TextField,
template: compile('{{view view.textField class="unbound" classBinding="App.isGreat:great App.isEnabled:enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled:really-enabled:really-disabled"}}')
});

expectDeprecation(function() {
runAppend(view);
});

ok(view.$('input').hasClass('unbound'), 'sets unbound classes directly');
ok(view.$('input').hasClass('great'), 'evaluates classBinding');
ok(view.$('input').hasClass('really-great'), 'evaluates classNameBinding');
ok(view.$('input').hasClass('enabled'), 'evaluates ternary operator in classBindings');
ok(view.$('input').hasClass('really-enabled'), 'evaluates ternary operator in classBindings');
ok(!view.$('input').hasClass('disabled'), 'evaluates ternary operator in classBindings');
ok(!view.$('input').hasClass('really-disabled'), 'evaluates ternary operator in classBindings');

run(function() {
App.set('isEnabled', false);
});

ok(!view.$('input').hasClass('enabled'), 'evaluates ternary operator in classBindings');
ok(!view.$('input').hasClass('really-enabled'), 'evaluates ternary operator in classBindings');
ok(view.$('input').hasClass('disabled'), 'evaluates ternary operator in classBindings');
ok(view.$('input').hasClass('really-disabled'), 'evaluates ternary operator in classBindings');

runDestroy(lookup.App);
});

QUnit.test('{{view}} should evaluate other attribute bindings set to global paths [DEPRECATED]', function() {
run(function() {
lookup.App = Namespace.create({
name: 'myApp'
});
});

var template;
expectDeprecation(function() {
template = compile('{{view view.textField valueBinding="App.name"}}');
}, /You're using legacy binding syntax: valueBinding/);

view = EmberView.create({
textField: TextField,
template
});

expectDeprecation(function() {
runAppend(view);
}, 'Global lookup of App from a Handlebars template is deprecated.');

equal(view.$('input').val(), 'myApp', 'evaluates attributes bound to global paths');

runDestroy(lookup.App);
});

QUnit.test('{{view}} should evaluate other attributes bindings set in the current context', function() {
view = EmberView.create({
name: 'myView',
Expand Down
30 changes: 0 additions & 30 deletions packages/ember-htmlbars/tests/helpers/with_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,6 @@ QUnit.test('nested {{with}} blocks shadow the outer scoped variable properly.',
equal(view.$().text(), 'Limbo-Wrath-Treachery-Wrath-Limbo', 'should be properly scoped after updating');
});

QUnit.module('Handlebars {{#with}} globals helper [DEPRECATED]', {
setup() {
Ember.lookup = lookup = { Ember: Ember };

lookup.Foo = { bar: 'baz' };
view = EmberView.create({
template: compile('{{#with Foo.bar as |qux|}}{{qux}}{{/with}}')
});
},

teardown() {
runDestroy(view);
Ember.lookup = originalLookup;
}
});

QUnit.test('it should support #with Foo.bar as |qux| [DEPRECATED]', function() {
expectDeprecation(function() {
runAppend(view);
}, /Global lookup of Foo from a Handlebars template is deprecated/);

equal(view.$().text(), 'baz', 'should be properly scoped');

run(function() {
set(lookup.Foo, 'bar', 'updated');
});

equal(view.$().text(), 'updated', 'should update');
});

QUnit.module('Handlebars {{#with keyword as |foo|}}');

QUnit.test('it should support #with view as |foo|', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { runAppend, runDestroy } from 'ember-runtime/tests/utils';

var view;

QUnit.module('ember-htmlbars: Integration with Globals', {
QUnit.module('ember-htmlbars: Escaped Integration', {
teardown() {
runDestroy(view);

Expand Down
Loading