From bc8903f40f9c2602978dd62a824e4c788fa72a7d Mon Sep 17 00:00:00 2001 From: Robbie Pitts Date: Tue, 26 Apr 2016 07:04:39 -0400 Subject: [PATCH] Ember.Binding deprecations --- .../integration/binding_integration_test.js | 17 +++-- .../tests/integration/helpers/unbound-test.js | 2 +- packages/ember-metal/lib/binding.js | 37 ++++++++++- .../ember-metal/tests/binding/connect_test.js | 54 +++++++++++++--- .../ember-metal/tests/binding/sync_test.js | 45 +++++++++++-- .../ember-runtime/tests/ext/mixin_test.js | 14 +++- .../mixins/observable/observable_test.js | 20 ++++-- .../tests/legacy_1x/system/binding_test.js | 64 ++++++++++++++----- .../legacy_1x/system/object/bindings_test.js | 56 ++++++++++++---- .../tests/legacy_1x/system/run_loop_test.js | 30 ++++++--- .../tests/system/object/create_test.js | 15 +++-- .../tests/system/object/destroy_test.js | 7 +- .../tests/system/object/subclasses_test.js | 19 ++++-- .../ember-views/tests/views/text_area_test.js | 12 +++- .../tests/views/text_field_test.js | 25 ++++++-- .../tests/views/view/view_lifecycle_test.js | 13 ++-- 16 files changed, 339 insertions(+), 91 deletions(-) diff --git a/packages/ember-glimmer/tests/integration/binding_integration_test.js b/packages/ember-glimmer/tests/integration/binding_integration_test.js index 758c40f776a..29147c52cd9 100644 --- a/packages/ember-glimmer/tests/integration/binding_integration_test.js +++ b/packages/ember-glimmer/tests/integration/binding_integration_test.js @@ -18,12 +18,17 @@ moduleFor('Binding integration tests', class extends RenderingTest { template: 'two way: {{twoWayTest}}, string: {{stringTest}}, object: {{twoWayObjectTest}}, string object: {{stringObjectTest}}' }); - this.render('{{foo-bar direction=direction displacement=displacement}}', { - direction: 'down', - displacement: { - distance: 10 - } - }); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + this.render('{{foo-bar direction=direction displacement=displacement}}', { + direction: 'down', + displacement: { + distance: 10 + } + }); + }, deprecationMessage); this.assertText('two way: down, string: down, object: 10, string object: 10'); diff --git a/packages/ember-glimmer/tests/integration/helpers/unbound-test.js b/packages/ember-glimmer/tests/integration/helpers/unbound-test.js index 3da4f61bcbe..ae4ab57ba5f 100644 --- a/packages/ember-glimmer/tests/integration/helpers/unbound-test.js +++ b/packages/ember-glimmer/tests/integration/helpers/unbound-test.js @@ -252,10 +252,10 @@ moduleFor('Helpers test: {{unbound}}', class extends RenderingTest { this.render(`{{unbound (repeat foo count=bar)}} {{repeat foo count=bar}} {{unbound (repeat foo count=2)}} {{repeat foo count=4}}`, { foo: 'X', - numRepeatsBinding: 'bar', bar: 5 }); + this.assertText('XXXXX XXXXX XX XXXX'); this.runTask(() => this.rerender()); diff --git a/packages/ember-metal/lib/binding.js b/packages/ember-metal/lib/binding.js index 121f4ae14f1..ad0a4e33e0f 100644 --- a/packages/ember-metal/lib/binding.js +++ b/packages/ember-metal/lib/binding.js @@ -1,7 +1,7 @@ import Logger from 'ember-console'; import { context, ENV } from 'ember-environment'; import run from 'ember-metal/run_loop'; -import { assert } from 'ember-metal/debug'; +import { assert, deprecate } from 'ember-metal/debug'; import { get } from 'ember-metal/property_get'; import { trySet } from 'ember-metal/property_set'; import { guidFor } from 'ember-metal/utils'; @@ -43,6 +43,7 @@ function Binding(toPath, fromPath) { /** @class Binding @namespace Ember + @deprecated See http://emberjs.com/deprecations/v2.x#toc_ember-binding @public */ @@ -144,13 +145,13 @@ Binding.prototype = { connect(obj) { assert('Must pass a valid object to Ember.Binding.connect()', !!obj); - let fromObj, fromPath; + let fromObj, fromPath, possibleGlobal; // If the binding's "from" path could be interpreted as a global, verify // whether the path refers to a global or not by consulting `Ember.lookup`. if (isGlobalPath(this._from)) { let name = getFirstKey(this._from); - let possibleGlobal = context.lookup[name]; + possibleGlobal = context.lookup[name]; if (possibleGlobal) { fromObj = possibleGlobal; @@ -175,6 +176,10 @@ Binding.prototype = { addListener(obj, 'willDestroy', this, 'disconnect'); + fireDeprecations(possibleGlobal, + this._oneWay, + (!possibleGlobal && !this._oneWay)); + this._readyToSync = true; this._fromObj = fromObj; this._fromPath = fromPath; @@ -281,6 +286,32 @@ Binding.prototype = { }; +function fireDeprecations(deprecateGlobal, deprecateOneWay, deprecateAlias) { + let deprecateGlobalMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + let deprecateOneWayMessage = '`Ember.Binding` is deprecated. Since you' + + ' are using a `oneWay` binding consider using a `readOnly` computed' + + ' property instead.'; + let deprecateAliasMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + deprecate(deprecateGlobalMessage, !deprecateGlobal, { + id: 'ember-metal.binding', + until: '3.0.0', + url: 'http://emberjs.com/deprecations/v2.x#toc_ember-binding' + }); + deprecate(deprecateOneWayMessage, !deprecateOneWay, { + id: 'ember-metal.binding', + until: '3.0.0', + url: 'http://emberjs.com/deprecations/v2.x#toc_ember-binding' + }); + deprecate(deprecateAliasMessage, !deprecateAlias, { + id: 'ember-metal.binding', + until: '3.0.0', + url: 'http://emberjs.com/deprecations/v2.x#toc_ember-binding' + }); +} + function mixinProperties(to, from) { for (var key in from) { if (from.hasOwnProperty(key)) { diff --git a/packages/ember-metal/tests/binding/connect_test.js b/packages/ember-metal/tests/binding/connect_test.js index 1a7b7b2a029..b56288ac679 100644 --- a/packages/ember-metal/tests/binding/connect_test.js +++ b/packages/ember-metal/tests/binding/connect_test.js @@ -54,7 +54,26 @@ testBoth('Connecting a binding between two properties', function(get, set) { // a.bar -> a.foo var binding = new Binding('foo', 'bar'); - performTest(binding, a, a, get, set); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + + ' `alias` computed property instead.'; + + expectDeprecation(() => { + performTest(binding, a, a, get, set); + }, deprecationMessage); +}); + +testBoth('Connecting a oneWay binding raises a deprecation', + function(get, set) { + var a = { foo: 'FOO', bar: 'BAR' }; + + // a.bar -> a.foo + var binding = new Binding('foo', 'bar').oneWay(); + + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are using a `oneWay` binding consider using a `readOnly` computed' + + ' property instead.'; + + expectDeprecation(() => { binding.connect(a); }, deprecationMessage); }); testBoth('Connecting a binding between two objects', function(get, set) { @@ -64,7 +83,12 @@ testBoth('Connecting a binding between two objects', function(get, set) { // b.bar -> a.foo var binding = new Binding('foo', 'b.bar'); - performTest(binding, a, b, get, set); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + + ' `alias` computed property instead.'; + + expectDeprecation(() => { + performTest(binding, a, b, get, set); + }, deprecationMessage); }); testBoth('Connecting a binding to path', function(get, set) { @@ -78,7 +102,12 @@ testBoth('Connecting a binding to path', function(get, set) { // globalB.b.bar -> a.foo var binding = new Binding('foo', 'GlobalB.b.bar'); - performTest(binding, a, b, get, set); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + performTest(binding, a, b, get, set); + }, deprecationMessage); // make sure modifications update b = { bar: 'BIFF' }; @@ -97,11 +126,15 @@ testBoth('Calling connect more than once', function(get, set) { // b.bar -> a.foo var binding = new Binding('foo', 'b.bar'); - performTest(binding, a, b, get, set, function () { - binding.connect(a); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + + ' `alias` computed property instead.'; - binding.connect(a); - }); + expectDeprecation(() => { + performTest(binding, a, b, get, set, function () { + binding.connect(a); + binding.connect(a); + }); + }, deprecationMessage); }); QUnit.test('inherited bindings should sync on create', function() { @@ -111,10 +144,13 @@ QUnit.test('inherited bindings should sync on create', function() { bind(this, 'foo', 'bar.baz'); }; - a = new A(); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider using an' + + ' `alias` computed property instead.'; + + expectDeprecation(() => { a = new A(); }, deprecationMessage); + set(a, 'bar', { baz: 'BAZ' }); }); equal(get(a, 'foo'), 'BAZ', 'should have synced binding on new obj'); }); - diff --git a/packages/ember-metal/tests/binding/sync_test.js b/packages/ember-metal/tests/binding/sync_test.js index 08315c62949..adb04149fad 100644 --- a/packages/ember-metal/tests/binding/sync_test.js +++ b/packages/ember-metal/tests/binding/sync_test.js @@ -35,7 +35,13 @@ testBoth('bindings should not sync twice in a single run loop', function(get, se b = { a: a }; - bind(b, 'foo', 'a.foo'); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(b, 'foo', 'a.foo'); + }, deprecationMessage); }); // reset after initial binding synchronization @@ -68,7 +74,13 @@ testBoth('bindings should not infinite loop if computed properties return object b = { a: a }; - bind(b, 'foo', 'a.foo'); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(b, 'foo', 'a.foo'); + }, deprecationMessage); }); deepEqual(get(b, 'foo'), ['foo', 'bar'], 'the binding should sync'); @@ -86,12 +98,21 @@ testBoth('bindings should do the right thing when observers trigger bindings in b = { a: a }; - bind(b, 'foo', 'a.foo'); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(b, 'foo', 'a.foo'); + }, deprecationMessage); c = { a: a }; - bind(c, 'foo', 'a.foo'); + + expectDeprecation(() => { + bind(c, 'foo', 'a.foo'); + }, deprecationMessage); }); addObserver(b, 'foo', function() { @@ -116,7 +137,13 @@ testBoth('bindings should not try to sync destroyed objects', function(get, set) b = { a: a }; - bind(b, 'foo', 'a.foo'); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(b, 'foo', 'a.foo'); + }, deprecationMessage); }); run(function() { @@ -133,7 +160,13 @@ testBoth('bindings should not try to sync destroyed objects', function(get, set) b = { a: a }; - bind(b, 'foo', 'a.foo'); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(b, 'foo', 'a.foo'); + }, deprecationMessage); }); run(function() { diff --git a/packages/ember-runtime/tests/ext/mixin_test.js b/packages/ember-runtime/tests/ext/mixin_test.js index f7640945cad..a2d1775a1fc 100644 --- a/packages/ember-runtime/tests/ext/mixin_test.js +++ b/packages/ember-runtime/tests/ext/mixin_test.js @@ -14,7 +14,12 @@ QUnit.test('Defining a property ending in Binding should setup binding when appl var obj = { bar: { baz: 'BIFF' } }; run(function() { - MyMixin.apply(obj); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + MyMixin.apply(obj); + }, deprecationMessage); }); ok(get(obj, 'fooBinding') instanceof Binding, 'should be a binding object'); @@ -33,7 +38,12 @@ QUnit.test('Defining a property ending in Binding should apply to prototype chil obj = { bar: { baz: 'BIFF' } }; run(function() { - MyMixin.apply(obj); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + MyMixin.apply(obj); + }, deprecationMessage); }); diff --git a/packages/ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js b/packages/ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js index 0081701efda..799d3bb92ea 100644 --- a/packages/ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js +++ b/packages/ember-runtime/tests/legacy_1x/mixins/observable/observable_test.js @@ -528,9 +528,14 @@ QUnit.test('nested dependent keys should propagate after they update', function( }) }); - bindObj = ObservableObject.extend({ - priceBinding: 'DepObj.price' - }).create(); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + bindObj = ObservableObject.extend({ + priceBinding: 'DepObj.price' + }).create(); + }, deprecationMessage); }); equal(bindObj.get('price'), 5, 'precond - binding propagates'); @@ -835,7 +840,7 @@ QUnit.test('removing an observer inside of an observer shouldn’t cause any pro -QUnit.module('Bind function ', { +QUnit.module('Bind function', { setup() { objectA = ObservableObject.create({ name: 'Sproutcore', @@ -865,7 +870,12 @@ QUnit.module('Bind function ', { QUnit.test('should bind property with method parameter as undefined', function() { // creating binding run(function() { - objectA.bind('name', 'Namespace.objectB.normal', undefined); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + objectA.bind('name', 'Namespace.objectB.normal', undefined); + }, deprecationMessage); }); // now make a change to see if the binding triggers. diff --git a/packages/ember-runtime/tests/legacy_1x/system/binding_test.js b/packages/ember-runtime/tests/legacy_1x/system/binding_test.js index ac2527d0519..3bc64b5bb48 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/binding_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/binding_test.js @@ -54,7 +54,12 @@ QUnit.module('basic object binding', { toObject = EmberObject.create({ value: 'end' }); root = { fromObject: fromObject, toObject: toObject }; run(function () { - binding = bind(root, 'toObject.value', 'fromObject.value'); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + binding = bind(root, 'toObject.value', 'fromObject.value'); + }, deprecationMessage); }); } }); @@ -101,8 +106,16 @@ QUnit.test('deferred observing during bindings', function() { var root = { fromObject: fromObject, toObject: toObject }; run(function () { - bind(root, 'toObject.value1', 'fromObject.value1'); - bind(root, 'toObject.value2', 'fromObject.value2'); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(root, 'toObject.value1', 'fromObject.value1'); + }, deprecationMessage); + + expectDeprecation(() => { + bind(root, 'toObject.value2', 'fromObject.value2'); + }, deprecationMessage); // change both value1 + value2, then flush bindings. observer should only // fire after bindings are done flushing. @@ -145,8 +158,17 @@ QUnit.module('chained binding', { third = EmberObject.create({ input: 'third' }); root = { first: first, second: second, third: third }; - binding1 = bind(root, 'second.input', 'first.output'); - binding2 = bind(root, 'second.output', 'third.input'); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + binding1 = bind(root, 'second.input', 'first.output'); + }, deprecationMessage); + + expectDeprecation(() => { + binding2 = bind(root, 'second.output', 'third.input'); + }, deprecationMessage); }); }, teardown() { @@ -216,12 +238,19 @@ QUnit.test('two bindings to the same value should sync in the order they are ini this._super(...arguments); set(this, 'c', this.C.create({ owner: this })); } - }).create({ - foo: 'baz', - fooBinding: 'a.foo', - a: a }); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + b = b.create({ + foo: 'baz', + fooBinding: 'a.foo', + a: a + }); + }, deprecationMessage); + run.end(); equal(get(a, 'foo'), 'bar', 'a.foo should not change'); @@ -243,12 +272,17 @@ QUnit.module('propertyNameBinding with longhand', { value: 'originalValue' }); - TestNamespace.toObject = EmberObject.extend({ - valueBinding: Binding.from('TestNamespace.fromObject.value'), - relativeBinding: Binding.from('localValue') - }).create({ - localValue: 'originalLocal' - }); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + TestNamespace.toObject = EmberObject.extend({ + valueBinding: Binding.from('TestNamespace.fromObject.value'), + relativeBinding: Binding.from('localValue') + }).create({ + localValue: 'originalLocal' + }); + }, deprecationMessage); }); }, teardown() { diff --git a/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js b/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js index bef3dd32215..d6abe7c1e99 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/object/bindings_test.js @@ -62,8 +62,13 @@ QUnit.module('bind() method', bindModuleOpts); QUnit.test('bind(TestNamespace.fromObject.bar) should follow absolute path', function() { run(function() { - // create binding - testObject.bind('foo', 'TestNamespace.fromObject.bar'); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + // create binding + testObject.bind('foo', 'TestNamespace.fromObject.bar'); + }, deprecationMessage); // now make a change to see if the binding triggers. set(fromObject, 'bar', 'changedValue'); @@ -74,8 +79,13 @@ QUnit.test('bind(TestNamespace.fromObject.bar) should follow absolute path', fun QUnit.test('bind(.bar) should bind to relative path', function() { run(function() { - // create binding - testObject.bind('foo', 'bar'); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + // create binding + testObject.bind('foo', 'bar'); + }, deprecationMessage); // now make a change to see if the binding triggers. set(testObject, 'bar', 'changedValue'); @@ -122,11 +132,16 @@ QUnit.module('fooBinding method', fooBindingModuleOpts); QUnit.test('fooBinding: TestNamespace.fromObject.bar should follow absolute path', function() { - // create binding run(function() { - testObject = TestObject.extend({ - fooBinding: 'TestNamespace.fromObject.bar' - }).create(); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + // create binding + testObject = TestObject.extend({ + fooBinding: 'TestNamespace.fromObject.bar' + }).create(); + }, deprecationMessage); // now make a change to see if the binding triggers. set(fromObject, 'bar', 'changedValue'); @@ -137,9 +152,16 @@ QUnit.test('fooBinding: TestNamespace.fromObject.bar should follow absolute path QUnit.test('fooBinding: .bar should bind to relative path', function() { run(function() { - testObject = TestObject.extend({ - fooBinding: 'bar' - }).create(); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + // create binding + testObject = TestObject.extend({ + fooBinding: 'bar' + }).create(); + }, deprecationMessage); + // now make a change to see if the binding triggers. set(testObject, 'bar', 'changedValue'); }); @@ -149,9 +171,15 @@ QUnit.test('fooBinding: .bar should bind to relative path', function() { QUnit.test('fooBinding: should disconnect bindings when destroyed', function () { run(function() { - testObject = TestObject.extend({ - fooBinding: 'TestNamespace.fromObject.bar' - }).create(); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + // create binding + testObject = TestObject.extend({ + fooBinding: 'TestNamespace.fromObject.bar' + }).create(); + }, deprecationMessage); set(TestNamespace.fromObject, 'bar', 'BAZ'); }); diff --git a/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js b/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js index 07a30681017..4c752b7dc80 100644 --- a/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js +++ b/packages/ember-runtime/tests/legacy_1x/system/run_loop_test.js @@ -44,13 +44,20 @@ QUnit.module('System:run_loop() - chained binding', { QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.RunLoop)', function() { run(function () { + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + //Binding of output of MyApp.first object to input of MyApp.second object - binding1 = Binding.from('first.output') - .to('second.input').connect(MyApp); + expectDeprecation(() => { + binding1 = Binding.from('first.output') + .to('second.input').connect(MyApp); + }, deprecationMessage); //Binding of output of MyApp.second object to input of MyApp.third object - binding2 = Binding.from('second.output') - .to('third.input').connect(MyApp); + expectDeprecation(() => { + binding2 = Binding.from('second.output') + .to('third.input').connect(MyApp); + }, deprecationMessage); }); run(function () { @@ -75,13 +82,20 @@ QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.R QUnit.test('Should propagate bindings after the RunLoop completes', function() { run(function () { + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + //Binding of output of MyApp.first object to input of MyApp.second object - binding1 = Binding.from('first.output') - .to('second.input').connect(MyApp); + expectDeprecation(() => { + binding1 = Binding.from('first.output') + .to('second.input').connect(MyApp); + }, deprecationMessage); //Binding of output of MyApp.second object to input of MyApp.third object - binding2 = Binding.from('second.output') - .to('third.input').connect(MyApp); + expectDeprecation(() => { + binding2 = Binding.from('second.output') + .to('third.input').connect(MyApp); + }, deprecationMessage); }); run(function () { diff --git a/packages/ember-runtime/tests/system/object/create_test.js b/packages/ember-runtime/tests/system/object/create_test.js index 502de53ef17..dd6855d0469 100644 --- a/packages/ember-runtime/tests/system/object/create_test.js +++ b/packages/ember-runtime/tests/system/object/create_test.js @@ -47,10 +47,17 @@ if (isEnabled('mandatory-setter')) { } QUnit.test('allows bindings to be defined', function() { - var obj = EmberObject.create({ - foo: 'foo', - barBinding: 'foo' - }); + let obj; + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + obj = EmberObject.create({ + foo: 'foo', + barBinding: 'foo' + }); + }, deprecationMessage); equal(obj.get('bar'), 'foo', 'The binding value is correct'); }); diff --git a/packages/ember-runtime/tests/system/object/destroy_test.js b/packages/ember-runtime/tests/system/object/destroy_test.js index b560271b807..08c86167b15 100644 --- a/packages/ember-runtime/tests/system/object/destroy_test.js +++ b/packages/ember-runtime/tests/system/object/destroy_test.js @@ -160,7 +160,12 @@ QUnit.test('bindings should be synced when are updated in the willDestroy hook', }); run(function() { - bind(foo, 'value', 'bar.value'); + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + bind(foo, 'value', 'bar.value'); + }, deprecationMessage); }); ok(bar.get('value') === false, 'the initial value has been bound'); diff --git a/packages/ember-runtime/tests/system/object/subclasses_test.js b/packages/ember-runtime/tests/system/object/subclasses_test.js index 11ca54655f2..68a86019eaa 100644 --- a/packages/ember-runtime/tests/system/object/subclasses_test.js +++ b/packages/ember-runtime/tests/system/object/subclasses_test.js @@ -14,8 +14,15 @@ QUnit.test('chains should copy forward to subclasses when prototype created', fu }, aBinding: 'obj.a' // add chain }); - // realize prototype - objWithChains = ObjectWithChains.create(); + + let deprecationMessage = '`Ember.Binding` is deprecated. Consider' + + ' using an `alias` computed property instead.'; + + expectDeprecation(() => { + // realize prototype + objWithChains = ObjectWithChains.create(); + }, deprecationMessage); + // should not copy chains from parent yet SubWithChains = ObjectWithChains.extend({ hiBinding: 'obj.hi', // add chain @@ -24,9 +31,13 @@ QUnit.test('chains should copy forward to subclasses when prototype created', fu }).property('hi'), // observe chain greetingBinding: 'hello' }); + SubSub = SubWithChains.extend(); - // should realize prototypes and copy forward chains - subSub = SubSub.create(); + + expectDeprecation(() => { + // should realize prototypes and copy forward chains + subSub = SubSub.create(); + }, deprecationMessage); }); equal(subSub.get('greeting'), 'hi world'); run(function () { diff --git a/packages/ember-views/tests/views/text_area_test.js b/packages/ember-views/tests/views/text_area_test.js index 55da5953609..a2c8dc43189 100644 --- a/packages/ember-views/tests/views/text_area_test.js +++ b/packages/ember-views/tests/views/text_area_test.js @@ -83,9 +83,15 @@ QUnit.test('text area value is updated when setting value property of view', fun QUnit.test('value binding works properly for inputs that haven\'t been created', function() { run(function() { textArea.destroy(); // destroy existing textarea - textArea = TextArea.create({ - valueBinding: 'TestObject.value' - }); + + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + textArea = TextArea.create({ + valueBinding: 'TestObject.value' + }); + }, deprecationMessage); }); equal(get(textArea, 'value'), null, 'precond - default value is null'); diff --git a/packages/ember-views/tests/views/text_field_test.js b/packages/ember-views/tests/views/text_field_test.js index d7824f28f4a..e183a40c36e 100644 --- a/packages/ember-views/tests/views/text_field_test.js +++ b/packages/ember-views/tests/views/text_field_test.js @@ -137,9 +137,15 @@ QUnit.test('input type is configurable when creating view', function() { QUnit.test('value binding works properly for inputs that haven\'t been created', function() { run(function() { textField.destroy(); // destroy existing textField - textField = TextField.create({ - valueBinding: 'TestObject.value' - }); + + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + textField = TextField.create({ + valueBinding: 'TestObject.value' + }); + }, deprecationMessage); }); equal(get(textField, 'value'), null, 'precond - default value is null'); @@ -160,9 +166,16 @@ QUnit.test('value binding works properly for inputs that haven\'t been created', QUnit.test('value binding sets value on the element', function() { run(function() { textField.destroy(); // destroy existing textField - textField = TextField.create({ - valueBinding: 'TestObject.value' - }); + + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + textField = TextField.create({ + valueBinding: 'TestObject.value' + }); + }, deprecationMessage); + textField.append(); }); diff --git a/packages/ember-views/tests/views/view/view_lifecycle_test.js b/packages/ember-views/tests/views/view/view_lifecycle_test.js index 4bb7a0522e1..4b80fc261f0 100644 --- a/packages/ember-views/tests/views/view/view_lifecycle_test.js +++ b/packages/ember-views/tests/views/view/view_lifecycle_test.js @@ -45,10 +45,15 @@ QUnit.test('should create and append a DOM element after bindings have synced', fakeThing: 'controllerPropertyValue' }); - view = EmberView.create({ - fooBinding: 'ViewTest.fakeController.fakeThing', - template: compile('{{view.foo}}') - }); + let deprecationMessage = '`Ember.Binding` is deprecated. Since you' + + ' are binding to a global consider using a service instead.'; + + expectDeprecation(() => { + view = EmberView.create({ + fooBinding: 'ViewTest.fakeController.fakeThing', + template: compile('{{view.foo}}') + }); + }, deprecationMessage); ok(!view.get('element'), 'precond - does not have an element before appending');